(~ ̄▽ ̄) ~*
(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