经典指数          
POJ
原因
597
浏览数
0
收藏数
 

After building his huge villa, Mr. Rich cannot help but notice that the interior walls look rather blank. To change that, he starts to hang paintings from his wonderful collection. But soon he realizes that it becomes quite difficult to find a place on the wall where a painting can be placed without overlapping other paintings. Now he needs a program which would tell him, given the already placed paintings, where to place the next painting without moving any other paintings (or indicating that this is impossible). Paintings have a rectangular shape and are to be placed parallel to the side of the wall. If you do not mind a nice reward from Mr. Rich, go on and solve the problem.输入描述 The first line of the input file contains a number representing the number of test cases to follow. Each test case starts with a line containing three numbers n, w and h. n is the number of paintings already hanging on the wall, w is the width of the wall and h is the height of the wall. The next n lines contain 4 integers x1, y1, x2, y2 each (0 You can assume输出描述 Produce one line of output for each test case. Write "Fail!" if there is no place left on the wall where the painting could be placed without overlapping other paintings. Otherwise, write the coordinates where the lower left corner of the painting should be placed. In case there is more than one solution, select the solution with a minimum y-coordinate, and break ties using the minimum x-coordinate.输入例子 2 1 10 9 5 4 10 9 9 5 2 10 10 5 5 10 10 0 0 4 3 3 4 输出例子 Fail! 4 0 Hint The following image illustrates the second sample test case:

     举报   纠错  
 
切换
1 个答案
#include #include #include using namespace std; int cas,n,w,h,ww,hh; struct ll{ int x1,x2,y1,y2; ll() {x1 = x2 = y1 = y2 = 0;} ll(int _x1,int _y1,int _x2,int _y2):x1(_x1),y1(_y1),x2(_x2),y2(_y2) {} }p[210]; bool isXJ(const ll &a,const ll &b) { if(a.x2 > b.x1 && a.y2 > b.y1 && b.x2 > a.x1 && b.y2 > a.y1) return true; return false; } int yall[500],xall[500],len,len1; bool check(int x,int y) { ll a(x,y,x + ww,y +hh); for(int i = 0;i < n;i ++) { if(isXJ(a,p[i])) return false; } return true; } int main(){ scanf("%d",&cas); while(cas--){ len = len1 = 0; yall[len ++] = 0; xall[len1 ++] = 0; scanf("%d%d%d",&n,&w,&h); for(int i = 0;i < n;i ++) { scanf("%d%d%d%d",&p[i].x1,&p[i].y1,&p[i].x2,&p[i].y2); xall[len1 ++] = p[i].x2; yall[len ++] = p[i].y2; } sort(xall,xall + len1); sort(yall,yall + len); scanf("%d%d",&ww,&hh); //for(int i = 0;i < len;i ++) // cout<<"y[i] = "< h - hh) break; for(int j = 0;j < len1;j ++) { if(xall[j] > w - ww) break; if(check(xall[j],yall[i])) { if(!flag) { flag = true; posx = xall[j]; posy = yall[i]; break; } } } if(flag) break; } if(flag) printf("%d %d\n",posx,posy); else printf("Fail!\n"); } }
 
切换
撰写答案
扫描后移动端查看本题