____________________________________________________________________
Question: Rectangles
____________________________________________________________________
#include "iostream.h"
int max(int a, int b) {
return (a > b)? a : b;
}
int min(int a, int b) {
return (a < b)? a : b;
}
int main()
{
int n;
cin >> n;
for(int i = 1; i <= n; i++) {
int m;
cin >> m;
int smallx, smally, bigx, bigy;
cin >> smallx >> smally >> bigx >> bigy;
int j;
for(j = 1; j < m; j++) {
int sx, sy, bx, by;
cin >> sx >> sy >> bx >> by;
smallx = max(smallx, sx);
smally = max(smally, sy);
bigx = min(bigx, bx);
bigy = min(bigy, by);
if(smallx > bigx || smally > bigy) break;
}
int dummy;
while(j++ < (m - 1)) cin >> dummy >> dummy >> dummy >> dummy;
long long int area = (bigx - smallx) * (bigy - smally);
if(area <= 0) area = 0;
cout << "Case " << i << ": " << area << endl;
}
return 0;
}
____________________________________________________________________
No comments:
Post a Comment