HDU 5128暴力

16660 ワード

HDU 5128タイトルリンク:http://acm.hdu.edu.cn/showproblem.php?pid=5128 标题:いくつかの点をあげて、任意に4つの点を選んで矩形1を構成して、更に異なる4つの点を選んで矩形2を構成します.合法的な状況(交差せず、公共の辺、点がない)の両者がカバーする平面面積とどれだけの構想かを聞く:大暴力、大シミュレーションとして書けばいい.1つの矩形が別の矩形を完全に覆う場合は合法であり、大きな矩形からの面積しか計算されないことに注意してください.ソース:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <stack>
using namespace std;
const int MAXN = 50 + 5;
const int MAXM = 200 + 5;
struct Point
{
    int x, y;
    Point(){}
    Point(int _x, int _y){x = _x, y = _y;}
}point[MAXN];
int gra[MAXM][MAXM];
bool cmp(Point a, Point b)
{
    if(a.x != b.x)  return a.x < b.x;
    else return a.y < b.y;
}
vector<int>col[MAXM];
int cur[MAXM];
int n;
int X1[5], Y1[5], X2[5], Y2[5];
//void check()
//{
//    printf("*******//////checking////////*********\n");
//    for(int i = 1 ; i <= 4 ; i++)
//        printf("x1[%d] = %d, y1[%d] = %d
"
, i, x1[i], i, y1[i]); // for(int i = 1 ; i <= 4 ; i++) // printf("x2[%d] = %d, y2[%d] = %d
"
, i, x2[i], i, y2[i]); // printf("*******//////checking////////*********\n"); // system("pause"); //} int cal() { // check(); if(X1[1] > X2[2] || X1[2] < X2[2] || Y1[3] < Y2[1] || Y1[1] > Y1[3]){ return (X2[4] - X2[1]) * (Y2[4] - Y2[1]) + (X1[4] - X1[1]) * (Y1[4] - Y1[1]); } else if(X1[1] < X2[1] && Y1[1] < Y2[1] && X1[4] > X2[4] && Y1[4] > Y2[4]){ return (X1[4] - X1[1]) * (Y1[4] - Y1[1]); } else if(X1[1] > X2[1] && Y1[1] > Y2[1] && X1[4] < X2[4] && Y1[4] < Y2[4]){ return (X2[4] - X2[1]) * (Y2[4] - Y2[1]); } else return -1; } int solve1(int x, int y, int cnt) { int ans = -1; int ne = cnt; while(ne <= n && point[ne].x == x) ne++; if(ne > n) return -1; // printf("ne = %d, n = %d, cnt = %d
"
, ne, n, cnt); for(int i = cnt + 1 ; i <= n ; i++){ if(point[i].x != x) break; for(int j = 0 ; j < (int)col[y].size() ; j++){ int now = col[y][j]; if(point[now].x <= x || now <= i) continue; X1[1] = x, Y1[1] = y; X1[2] = point[now].x, Y1[2] = point[now].y; X1[3] = point[i].x, Y1[3] = point[i].y; X1[4] = point[now].x, Y1[4] = point[i].y; // for(int k = 1 ; k <= 4 ; k++){ // printf("x1[%d] = %d, y1[%d] = %d
"
, k, x1[k], k, y1[k]); // } // system("pause"); if(gra[X1[4]][Y1[4]] != 0){ // printf("hahah
"
); for(int lv = i + 1 ; lv <= n ; lv++){ int tx = point[lv].x, ty = point[lv].y; for(int t1 = lv + 1 ; t1 <= n ; t1++){ if(point[t1].x != tx){ // printf("first
"
); break; } for(int t2 = 0 ; t2 < (int)col[ty].size() ; t2++){ // printf("fsafsa
"
); if(point[col[ty][t2]].x <= tx) continue; int tnow = col[ty][t2]; X2[1] = tx, Y2[1] = ty; X2[2] = point[t1].x, Y2[2] = point[t1].y; X2[3] = point[tnow].x, Y2[3] = point[tnow].y; X2[4] = point[tnow].x, Y2[4] = point[t1].y; // for(int k = 1 ; k <= 4 ; k++){ // printf("x2[%d] = %d, y2[%d] = %d
"
, k, x2[k], k, y2[k]); // } // printf("second
"
); if(gra[X2[4]][Y2[4]] == 0) continue; ans = max(ans, cal()); } } } } } } return ans; } int main() { // freopen("HDU 5128.in", "r", stdin); while(scanf("%d", &n) != EOF && n){ for(int i = 1 ; i <= n ; i++){ scanf("%d%d", &point[i].x, &point[i].y); } sort(point + 1, point + n + 1, cmp); memset(gra, 0, sizeof(gra)); for(int i = 0 ; i < MAXM ; i++) col[i].clear(), cur[i] = 0; for(int i = 1 ; i <= n ; i++){ gra[point[i].x][point[i].y] = i; col[point[i].y].push_back(i); } int ans = -1; for(int i = 1 ; i <= n ; i++){ int x = point[i].x; int y = point[i].y; // cur[x]++; ans = max(ans, solve1(x, y, i)); } if(ans == -1) printf("imp
"
); else printf("%d
"
, ans); } return 0; }