地址:http://acm.hdu.edu.cn/showproblem.php?pid=1264
题意:给许多矩形,求面积并。坐标是0到100内的整数。
mark:把矩形覆盖的区域赋值为1。。。
代码:
1 # include <stdio.h> 2 3 4 int g[110][110] ; 5 6 7 int main () 8 { 9 int a, b, c, d, t, i, j, ans ; 10 while (~scanf ("%d%d%d%d", &a, &b, &c, &d)) 11 { 12 if (a == -1 && b == -1 && c == -1 && d == -1) 13 { 14 ans = 0 ; 15 for (i = 0 ; i < 101 ; i++) 16 for (j = 0 ; j < 101 ; j++) 17 ans += g[i][j], g[i][j] = 0 ; 18 printf ("%d ", ans) ; 19 } 20 else if (a == -2 && b == -2 && c == -2 && d == -2) 21 { 22 ans = 0 ; 23 for (i = 0 ; i < 101 ; i++) 24 for (j = 0 ; j < 101 ; j++) 25 ans += g[i][j], g[i][j] = 0 ; 26 printf ("%d ", ans) ; 27 break ; 28 } 29 else 30 { 31 if (a > c) t = c, c=a, a= t ; 32 if (b > d) t = d, d = b, b = t ; 33 for (i = a ; i < c ; i++) 34 for (j = b ; j < d; j++) 35 g[i][j] = 1 ; 36 } 37 } 38 return 0 ; 39 }