24h購物| | PChome| 登入
2012-09-29 20:31:22| 人氣2,259| 回應0 | 上一篇 | 下一篇

[UVA][幾何] 11345 - Rectangles

推薦 0 收藏 0 轉貼0 訂閱站台

F - Rectangles

Time Limit: 1 sec
Memory Limit: 16MB

This problem has no story. You just have to find the common area of all rectangles.

INPUT:

The first line contains integer N (1 <= N <= 1000). It is the number of tests. Each test described by number of rectangles M (1 <= M <= 30). Next N lines contain 4 integers: X1 Y1 X2 Y2 (-10000 <= X1; Y2; X2; Y2 <= 10000). Each rectangle is described by 2 points: lower left and upper right corners. All rectangle sides are parallel to Ox or Oy axes.

OUTPUT:

For each test case out line formatter like this: "Case i: a". Where "i" is a test number, and "a" is an area that belongs to all rectangles.

SAMPLE INPUT:

1
4
0 0 10 10
-1 -1 2 2
-10 0 2 100
-10 -10 10 10

SAMPLE OUTPUT:

Case 1: 4

給的時候就是給定左下, 右上, 如果顛倒, 直接輸出 0,
特別記住 n = 1 的時候, 應該很多人會卡死這種測資

#include <stdio.h>
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))
typedef struct {
int x, y;
} Pt;
int main() {
int t, cases = 0, n;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
Pt a, b, c, d;
int i, j, k, l, tmp;
n--;
scanf("%d %d %d %d", &a.x, &a.y, &b.x, &b.y);
i = a.x, j = a.y, k = b.x, l = b.y;
int flag = 0;
while(n--) {
scanf("%d %d %d %d", &c.x, &c.y, &d.x, &d.y);
i = max(a.x, c.x), j = max(a.y, c.y);
k = min(b.x, d.x), l = min(b.y, d.y);
if(i >= k || j >= l) {
flag = -1;
} else {
a.x = i, a.y = j, b.x = k, b.y = l;
}
}
if(i >= k || j >= l) flag = -1;
printf("Case %d: ", ++cases);
if(!flag) printf("%d\n", (i-k)*(j-l));
else printf("0\n");
}
return 0;
}
 

台長: Morris
人氣(2,259) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][二分搜] 11876 - N + NOD (N)
此分類上一篇:[UVA][幾何、交集] 11639 - Guard the Land

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文