HDU 5128 暴力
2015-10-08 23:32
218 查看
HDU 5128
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5128
题意:
给一些点,问任意选四个点组成矩形1,再选不同的四个点组成矩形2。问在合法情况(不相交,无公共边、点)两者覆盖的平面面积和是多少
思路:
大暴力,当作大模拟写就行。注意一个矩形完全覆盖另一个矩形的情况是合法的,只算大矩形到的面积。
源码:
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5128
题意:
给一些点,问任意选四个点组成矩形1,再选不同的四个点组成矩形2。问在合法情况(不相交,无公共边、点)两者覆盖的平面面积和是多少
思路:
大暴力,当作大模拟写就行。注意一个矩形完全覆盖另一个矩形的情况是合法的,只算大矩形到的面积。
源码:
#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\n", i, x1[i], i, y1[i]); // for(int i = 1 ; i <= 4 ; i++) // printf("x2[%d] = %d, y2[%d] = %d\n", 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\n", 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\n", k, x1[k], k, y1[k]); // } // system("pause"); if(gra[X1[4]][Y1[4]] != 0){ // printf("hahah\n"); 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\n"); break; } for(int t2 = 0 ; t2 < (int)col[ty].size() ; t2++){ // printf("fsafsa\n"); 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\n", k, x2[k], k, y2[k]); // } // printf("second\n"); 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\n"); else printf("%d\n", ans); } return 0; }
相关文章推荐
- PHP实现html生成pdf、html生成图片 利用wkhtmltox,wkhtmltopdf扩展
- 《Effective STL》条款3-条款4
- 《微软的软件测试之道》读书笔记
- HDU 5136 DP
- HDU4903The only survival(clj计数问题ppt)
- Python的哲学
- AugularJS特性
- php——composer 1、安装使用
- 黑马程序员-------封装 继承 多态 的一些概念
- 高手对了网站搜索可用性的一些总结
- 包的应用
- 目标检测——CodeBook背景建模(原理+Opencv实现代码)
- BestCoder Round #56 (div.2) HDU5463 Clarke and minecraft
- 浏览器刷新缓存机制
- HDU 3746 Cyclic Nacklace
- shop++源代码
- 使用java代码生成图片验证码
- HashSet:底层数据结构是哈希表
- 黑马程序员--C语言之数组的定义以及使用
- Object类