标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 483 Accepted Submission(s): 203
#include <cstdio> #include <iostream> #include <cstdlib> #include <algorithm> #include <ctime> #include <cmath> #include <string> #include <cstring> #include <stack> #include <queue> #include <list> #include <vector> #include <map> #include <set> using namespace std; const int INF=0x3f3f3f3f; const double eps=1e-10; const double PI=acos(-1.0); #define maxn 50 struct Rect { int x1, x2, y1, y2, val; bool operator < (const Rect &r) const{ return val < r.val; } }; Rect r[maxn]; int val[maxn][maxn]; int x[maxn], y[maxn]; int main() { int t, n; int cas = 0; scanf("%d", &t); while(t--) { scanf("%d", &n); int cnt = 0 ; for(int i = 0; i < n; i++,cnt+=2) { scanf("%d%d%d%d%d", &r[i].x1, &r[i].y1, &r[i].x2, &r[i].y2, &r[i].val); x[cnt] = r[i].x1; x[cnt+1] = r[i].x2; y[cnt] = r[i].y1; y[cnt+1] = r[i].y2; } sort(r, r + n); sort(x, x + cnt); sort(y, y + cnt); memset(val, 0, sizeof val); for(int i = 0; i < n; i++) { int x1 = lower_bound(x, x + cnt, r[i].x1) - x; int x2 = lower_bound(x, x + cnt, r[i].x2) - x; int y1 = lower_bound(y, y + cnt, r[i].y1) - y; int y2 = lower_bound(y, y + cnt, r[i].y2) - y; //printf("%d %d %d %d\n", x1, x2, y1, y2); for(int j = x1; j < x2; j++) for(int k = y1; k < y2; k++)//将一个大矩形,分成一个一个小矩形。 val[j][k] = r[i].val; } long long ans = 0; for(int i = 0; i < cnt-1; i++) for(int j = 0; j < cnt-1; j++) ans +=(long long) val[i][j]*(x[i+1] - x[i]) *(y[j+1] - y[j]); printf("Case %d: %I64d\n", ++cas, ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/ZP-Better/p/4734380.html