标签:
题目大意:给你n个点,让你组成矩形,然后如果有两个矩形不相交的话就计算他们的面积,求最大的两个矩形的面积并。注意的是回字型的嵌套,面积的并是最大的矩形的面积。
解题思路:暴力,枚举出来矩形,然后再暴力枚举两个矩形判断是否相交,是否为回字型。
8 0 0 1 0 0 1 1 1 0 2 1 2 0 3 1 3 8 0 0 2 0 0 2 2 2 1 2 3 2 1 3 3 3 0
2 imp
#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include <iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include <stack> #include <ctime> #include <map> #include <set> #define eps 1e-9 ///#define M 1000100 ///#define LL __int64 #define LL long long ///#define INF 0x7ffffff #define INF 0x3f3f3f3f #define PI 3.1415926535898 #define zero(x) ((fabs(x)<eps)?0:x) #define mod 1000000007 #define Read() freopen("autocomplete.in","r",stdin) #define Write() freopen("autocomplete.out","w",stdout) #define Cin() ios::sync_with_stdio(false) using namespace std; inline int read() { char ch; bool flag = false; int a = 0; while(!((((ch = getchar()) >= '0') && (ch <= '9')) || (ch == '-'))); if(ch != '-') { a *= 10; a += ch - '0'; } else { flag = true; } while(((ch = getchar()) >= '0') && (ch <= '9')) { a *= 10; a += ch - '0'; } if(flag) { a = -a; } return a; } void write(int a) { if(a < 0) { putchar('-'); a = -a; } if(a >= 10) { write(a / 10); } putchar(a % 10 + '0'); } const int maxn = 201; int mp[maxn][maxn]; struct node { int x, y; } f[maxn]; int vis[maxn]; struct node1 { int num[4]; }p[maxn]; int main() { int n; while(~scanf("%d",&n) && n) { memset(mp, 0, sizeof(mp)); for(int i = 1; i <= n; i++) { scanf("%d %d",&f[i].x, &f[i].y); mp[f[i].x][f[i].y] = i; } int ans = 0; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if(i == j) continue; if(f[i].x <= f[j].x || f[i].y <= f[j].y) continue; int x1 = f[j].x; int y1 = f[i].y; int xp1 = mp[x1][y1]; if(!xp1) continue; int x2 = f[i].x; int y2 = f[j].y; int xp2 = mp[x2][y2]; if(!xp2) continue; p[ans].num[0] = i; p[ans].num[1] = j; p[ans].num[2] = xp1; p[ans++].num[3] = xp2; } } int Max = 0; for(int i = 0; i < ans; i++) { for(int j = 0; j < ans; j++) { if(i == j) continue; int flag = 0; for(int sk = 0; sk < 4; sk++) { for(int sp = 0; sp < 4; sp++) { if(p[i].num[sk] == p[j].num[sp]) { flag = 1; break; } } } if(flag) continue; int a1 = p[i].num[0]; int b1 = p[i].num[1]; int a2 = p[j].num[0]; int b2 = p[j].num[1]; if(f[b1].x < f[b2].x && f[b1].y < f[b2].y && f[a2].x < f[a1].x && f[a2].y < f[a1].y) { Max = max(Max, (f[a1].x-f[b1].x)*(f[a1].y-f[b1].y)); continue; } if(f[b2].x < f[b1].x && f[b2].y < f[b1].y && f[a1].x < f[a2].x && f[a1].y < f[a2].y) { Max = max(Max, (f[a2].x-f[b2].x)*(f[a2].y-f[b2].y)); continue; } if(f[b1].x <= f[b2].x && f[b2].x <= f[a1].x && f[b1].y <= f[b2].y && f[b2].y <= f[a1].y && (f[a2].x >= f[a1].x || f[a2].y >= f[a1].y)) { continue; } if(f[b1].x <= f[a2].x && f[a2].x <= f[a1].x && f[b1].y <= f[a2].y && f[a2].y <= f[a1].y && (f[b2].x <= f[b1].x || f[b2].y <= f[b1].y)) { continue; } int c1 = p[i].num[2]; int d1 = p[i].num[3]; int c2 = p[j].num[2]; int d2 = p[j].num[3]; if(f[c1].x <= f[c2].x && f[c2].x <= f[d1].x && f[d1].y <= f[c2].y && f[c2].y <= f[c1].y && (f[d2].x >= f[d1].x || f[d2].y <= f[d1].y)) { continue; } if(f[c1].x<=f[d2].x && f[d2].x <= f[d1].x && f[d1].y <= f[d2].y && f[d2].y <= f[c1].y && (f[c2].x <= f[c1].x || f[c2].y >= f[c1].y)) { continue; } int sx = (f[a1].x-f[b1].x)*(f[a1].y-f[b1].y); int sy = (f[a2].x-f[b2].x)*(f[a2].y-f[b2].y); if(f[a1].x == f[a2].x && (f[a1].y <= f[a2].y && f[d1].y >= f[d2].y)) { continue; } if(f[b1].x == f[b2].x && (f[c1].y <= f[c2].y && f[b1].y >= f[b2].y)) { continue; } if(f[a1].y == f[a2].y && (f[c2].x <= f[c1].x && f[a1].x <= f[a2].x)) { continue; } if(f[b1].y == f[b2].y && f[b2].x <= f[b1].x && f[d1].x <= f[d2].x) { continue; } Max = max(sx+sy, Max); } } if(!Max) cout<<"imp"<<endl; else cout<<Max<<endl; } } /* 8 0 0 0 3 3 3 3 0 1 1 1 2 2 2 2 1 */
HDU 5128 The E-pang Palace(暴力瞎搞)
标签:
原文地址:http://blog.csdn.net/xu12110501127/article/details/42917945