UVALive - 2689 Cricket Field
2014-01-23 20:34
316 查看
题意:求最大的空的矩形,要求不包含任何点
思路:边输入边记录,没增加一个点就将包含它的矩形切成四个小矩形
思路:边输入边记录,没增加一个点就将包含它的矩形切成四个小矩形
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 1000005; struct node{ int x,y; int w,h; }arr[MAXN]; int n,W,H; int main(){ int t; scanf("%d",&t); while (t--){ scanf("%d%d%d",&n,&W,&H); int cnt = 0; arr[cnt].x = arr[cnt].y = 0; arr[cnt].w = W,arr[cnt].h = H; cnt++; for (int i = 0; i < n; i++){ int a,b; scanf("%d%d",&a,&b); for (int j = 0; j < cnt; j++){ int x = arr[j].x,y = arr[j].y; int w = arr[j].w,h = arr[j].h; if (a > x && a < x+w && b > y && b < y+h){ arr[cnt].x = x,arr[cnt].y = y; arr[cnt].w = w,arr[cnt++].h = b - y; arr[cnt].x = x,arr[cnt].y = y; arr[cnt].w = a-x,arr[cnt++].h = h; arr[cnt].x = a,arr[cnt].y = y; arr[cnt].w = w-a+x,arr[cnt++].h = h; arr[cnt].x = x,arr[cnt].y = b; arr[cnt].w = w,arr[cnt++].h = h-b+y; arr[j].w = 0; } } } int ans = 0,sign; for (int i = 0; i < cnt; i++){ int temp = min(arr[i].w,arr[i].h); if (ans < temp){ ans = temp; sign = i; } } printf("%d %d %d\n",arr[sign].x,arr[sign].y,ans); if (t) printf("\n"); } return 0; }
相关文章推荐
- UVALive - 2689 Cricket Field
- UVALive 2689 极大子正方形
- UVALive 5797解题报告
- UVALive - 7464 Robots 贪心+递归
- UVALive 6571 It Can Be Arranged
- 2015暑假训练(UVALive 5983 - 5992)线段树离线处理+dp+floyed最短路
- UVALive 6436 The Busiest City
- UVALive 3887 Slim Span(枚举+MST,4级)
- UVALive 6163(暴力枚举)
- UVA Live 6557 Stampede! (uestc oj 871) 最大流+二分
- UVALive 4807||SYSU 2379 Cocircular Points 几何
- UVALive 6255 Kingdoms --状态搜索
- UVALive - 4487 Exclusive-OR 加权并查集
- UVALive 3266 田忌赛马
- UVALive 3177 - 长城守卫(二分+贪心)
- [UVALive 6955 Finding Lines]概率+随机算法
- 【暑假】[深入动态规划]UVAlive 3983 Robotruck
- UVALive5876-Writings on the Wall-KMP
- UVALive - 6266 Admiral 费用流
- UVALive - 6268 Cycling 贪心