Hdoj 5128 The E-pang Palace Violent enumeration + computational geometry

Source: Internet
Author: User


Enumerate each rectangle and judge the intersection

If it is a back font then the area of the output large rectangle ....

The E-pang PalaceTime limit:2000/1000 MS (java/others) Memory limit:512000/512000 K (java/others)
Total submission (s): Accepted submission (s): 26


Problem Descriptione-pang Palace was built in Qin dynasty by Emperor Qin Shihuang in Xianyang, Shanxi province. It is the largest palace ever built by human. It is so large and so magnificent the after many years of construction, it still is not completed. Building the Great Wall, E-pang Palace and Qin Shihuang ' s tomb cost so much labor and human lives that people rose to figh T against Qin Shihuang ' s regime.

Xiang Yu and Liu Bang were, rebel leaders at that time. Liu Bang captured Xianyang-the capital of Qin. Xiang Yu was very angry on this, and he commanded his army to march to Xianyang. Xiang Yu was the bravest and the strongest warrior at that time, and he army was much more than Liu Bang ' s. So Liu Bang is frighten and retreated from Xianyang, leaving all treasures in the grand E-pang Palace untouched. When Xiang Yu took Xianyang, he burned E-pang palce. The fire lasted for more than three months, renouncing the end of Qin dynasty.

Several years later, Liu Bang defeated Xiangyu and became the first emperor of Han dynasty. He went back to E-pang Palace but saw only some pillars left. Zhang Liang and Xiao He were Liu Bang ' s the most important ministers, so Liu Bang wanted to give them some awards. Liu Bang told them: "You guys can make both rectangular fences in E-pang Palace and then the land inside the fences would belon GS to you. But the corners of the rectangles must is the pillars left on the ground, and both fences can ' t cross or touch all other. "

To simplify the problem, E-pang Palace can be consider as a plane, and pillars can is considered as points on the plane. The fences is rectangles, and you must make the rectangles. Please note that the rectangles must is parallel to the coordinate axes.

The figures below shows 3 situations which is not qualified (Thick dots stands for pillars):


Zhang Liang and Xiao He wanted the total area of their land in E-pang Palace to be maximum. Please bring your computer, and go back to Han dynasty to help them so, the history of the change.
Inputthere is no more than the test case.

For each test case:

The first line is a integer n, meaning that there be N pillars left in E-pang Palace (4 <=n <= 30).

Then N lines follow. Each line contains integers x and y (0 <= x, y <=), indicating a pillar ' s coordinate. No. Pillars has the same coordinate.

The input ends by N = 0.
Outputfor each test case, print the maximum total area of land Zhang Liang and Xiao He could get. If it is impossible for them to build, qualified fences, print "imp".
Sample Input
80 01 00 11 10 21 20 31 380 02 00 22 21 23 21 33 30

Sample Output
2imp

SOURCE2014ACM/ICPC Asia Guangzhou Station-re-match (thanks to Chinese laborers and PKU)


#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Vector> #include <set>using namespace std;const int maxn = 31;int N,x[maxn],y[maxn];bool vis[201][201];struct Point{int x, y;}; struct matrix{point p[4];int area;}; Vector<matrix> Mat;bool Inside (int& kind,point p,matrix m) {int Sx=m.p[0].x,dx=m.p[2].x;int sy=m.p[0].y,dy= M.p[2].y;if ((P.X&GT;SX&AMP;&AMP;P.X&LT;DX) && (P.y>sy&&p.y<dy)) kind=1;if ((p.x>=sx& &AMP;P.X&LT;=DX) && (p.y>=sy&&p.y<=dy)) return True;return false;} int check (int a,int b) {MATRIX a=mat[a],b=mat[b];int k0=0,k1=0,k2=0,k3=0;bool ok0=inside (k0,a.p[0],b); bool Ok1=inside ( K1,A.P[1],B); bool Ok2=inside (K2,A.P[2],B); bool Ok3=inside (K3,A.P[3],B);///Maybe A all in side Bif (ok0| | ok1| | ok2| | OK3) {if (k0==1&&k1==1&&k2==1&&k3==1) return b.area;else return-999;} K0=0,k1=0,k2=0,k3=0;ok0=inside (K0,b.p[0],a); Ok1=inside (k1,b.p[1],a); ok2=inside(k2,b.p[2],a); Ok3=inside (k3,b.p[3],a);///Maybe B all in side Aif (ok0| | ok1| | ok2| | OK3) {if (k0==1&&k1==1&&k2==1&&k3==1) return a.area;else return-999;} A out of B and b out of Aif (Ok0==false&&ok1==false&&ok2==false&&ok3==false) {return a.area+ B.area;} return-999;} int main () {while (scanf ("%d", &n)!=eof&&n) {///initmemset (vis,0,sizeof (Vis)); Mat.clear (); for (int i=0;i <n;i++) {cin>>x[i]>>y[i];vis[x[i]][y[i]]=true;} Find all sqrfor (int i=0;i<n;i++) {for (int j=i+1;j<n;j++) {if (X[i]==x[j]) continue;if (Y[i]==y[j]) continue;int Sx=min (X[i],x[j]), Dx=max (X[i],x[j]), int sy=min (y[i],y[j]), Dy=max (Y[i],y[j]); if (Vis[sx][sy]&&vis[dx][sy] &&vis[sx][dy]&&vis[dx][dy]) {//This is a Sqrtmatrix m;m.p[0].x=sx,m.p[0].y=sy;m.p[1].x=dx,m.p[1].y =sy;m.p[2].x=dx,m.p[2].y=dy;m.p[3].x=sx,m.p[3].y=dy;m.area= (DX-SX) * (Dy-sy); Mat.push_back (M);}} int Ans=-1;int sz=mat.size (); for (int. i=0;i<sz;i++) {for (int j=i+1;j<sz;j++) {////Judgment 4 Rectangle intersection Ans=max (Ans,check (I,j));}} if (ans<0) puts ("imp"), Else printf ("%d\n", ans); return 0;}



Hdoj 5128 The E-pang Palace Violent enumeration + computational geometry

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.