POJ 1230 pass-muraille# greedy +vector iterator usage

Source: Internet
Author: User

(~ ̄▽ ̄) ~*

(Note the use of iterator in the code below, which draws on a bull)

#include <iostream>#include<cstdio>#include<vector>#include<cstring>using namespacestd;structwall{intRow//to indicate the line of the wall    intLeft ; intRight ;};intcol[ the];//Save the number of walls per columnVector<wall>Wall;intMain () {intT,n,k,ax,ay,bx,by; scanf ("%d",&t);  while(t--) {wall.clear (); memset (col,0,sizeof(col)); scanf ("%d%d",&n,&k); intmaxright=0; intCnt=0;  while(n--) {scanf ("%d%d%d%d",&ax,&ay,&bx,&by ); if(ax>bx) swap (AX,BX);//It is possible to enter the right endpoint of the wall first            if(bx>maxright) Maxright=BX;            Wall temp; Temp.row=ay; Temp.left=ax; temp.right=x;            Wall.push_back (temp);  for(inti=ax;i<=bx;i++) Col[i]++; }        intMaxt;  for(intI=0; i<=maxright;i++)        {//The front maxright records the right end of all the walls so that when you traverse it, the maxright ends .             while(col[i]>k) {//traversing each column, when the number of walls in the column >k, it means that the wall has to be deletedVector<wall>::iterator It=wall.begin ();//Traversal iteratorVector<wall>::iterator ITER;//Temporary iteratorsmaxt=0;  while(it!=Wall.end ()) {//Delete the wall with the largest (right greater than MAXT) (in the ITER record) (Erase vector element wall in the first element)                    if((*it). left<=i) {if((*it) .right>maxt) {Maxt=(*it). Right; ITER=it; }} it++; }                 for(intJ= (*iter). left;j<= (*iter). right;j++) Col[j]--;//Delete the wall-related recordsWall.erase (ITER);//Remove the wallcnt++; }} printf ("%d\n", CNT); }    return 0;}

POJ 1230 pass-muraille# greedy +vector iterator usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.