前两天练的了,
做了过的人最多的三道后
----------
wtw发现第一题据说是西工大说的那个暴力出奇迹的题
第四题刚推出轨迹是个圆,,syh发现 ,,, 求的是圆和多边形的面积交---
于是弃疗又开了另一场比赛----
从30个点里面选择8个点组成两个矩形,使得它们的面积和最大
枚举每个矩形的左下,右上这两个点---
虽然意识到了有大矩形包含小矩形的情况----
这种包含的情况的时候,只算外面那个大矩形的面积----(sb地还把两个加起来----wa了一天---好忧桑---)
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> using namespace std; typedef pair<int,int> pii; int n; int g[505][505]; struct node{ int x,y; }p[55]; int res; int xx1,yy1,xx2,yy2,xx3,yy3,xx4,yy4; int x1,y1,x2,y2,x3,y3,x4,y4; int check(){ if(x3 < x1 && y3 < y1 && x4 > x2 && y4 > y2) return 2; if(x3 > x2) return 1; if(y3 > y2) return 1; if(x4 < x1) return 1; if(y4 < y1) return 1; if(x3 == x2 && (y3 > y2 || yy3 < y1)) return 1; if(y3 == y2 && (x3 > x2 || xx4 < x1)) return 1; if(x4 == x1 && (yy4 > yy1 || y4 < y1)) return 1; if(y4 == y1 && (x4 < x1 || xx3 > xx2)) return 1; return 0; } int ok(){ vector<pii> cc; int num = 0; if(g[xx1][yy1]){ num++; g[xx1][yy1] = 0; cc.push_back(make_pair(xx1,yy1)); } if(g[xx2][yy2]){ num++; g[xx2][yy2] = 0; cc.push_back(make_pair(xx2,yy2)); } if(g[xx3][yy3]){ num++; g[xx3][yy3] = 0; cc.push_back(make_pair(xx3,yy3)); } if(g[xx4][yy4]){ num++; g[xx4][yy4] = 0; cc.push_back(make_pair(xx4,yy4)); } for(int i = 0;i < cc.size();i++){ int fi = cc[i].first,se = cc[i].second; g[fi][se] = 1; } return num == 4; } void work(int n1,int n2,int n3,int n4){ int q[5]; q[1] = n1;q[2] = n2;q[3] = n3;q[4] = n4; do{ x1 = p[q[1]].x; y1 = p[q[1]].y; x2 = p[q[2]].x; y2 = p[q[2]].y; x3 = p[q[3]].x; y3 = p[q[3]].y; x4 = p[q[4]].x; y4 = p[q[4]].y; if(x1 >= x2 || y1 >= y2) continue; if(x3 >= x4 || y3 >= y4) continue; int a = x2-x1; int b = y2-y1; int c = x4-x3; int d = y4-y3; xx1 = x1;yy1 = y1 + b; xx2 = x1 + a;yy2 = y1; xx3 = x3;yy3 = y3 + d; xx4 = x3 + c;yy4 = y3; if(!ok()) continue; if(check() == 1) { res = max(res,a*b + c*d); //for(int i = 1;i <= 4;i++) printf("q[%d] = %d\n",i,q[i]); } if(check() == 2){ res = max(res,max(a*b,c*d)); } }while(next_permutation(q+1,q+5)); } void solve(){ if(n <= 7){ puts("imp"); return; } res = -1; for(int i = 1;i <= n;i++){ for(int j = i+1;j <= n;j++){ for(int k = j+1;k <= n;k++){ for(int z = k+1;z <= n;z++){ // printf("i = %d j = %d k = %d z = %d\n",i,j,k,z); work(i,j,k,z); } } } } if(res == -1) puts("imp"); else printf("%d\n",res); } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); while(scanf("%d",&n) != EOF && n){ memset(g,0,sizeof(g)); for(int i = 1;i <= n;i++){ scanf("%d %d",&p[i].x,&p[i].y); g[p[i].x][p[i].y] = 1; } solve(); } return 0; }
Little Zu Chongzhi‘s Triangles
How Many Maos Does the Guanxi Worth
时间: 2024-10-13 01:46:08