标签:rap points div rect otherwise opp code content integer
InputThe input format is a series of lines, each containing 4 integers. Four -1‘s are used to separate problems, and four -2‘s are used to end the last problem. Otherwise, the numbers are the x-ycoordinates of two points that are opposite corners of a rectangle.
OutputYour output should be the number of squares covered by each set of rectangles. Each number should be printed on a separate line.
Sample Input
5 8 7 10 6 9 7 8 6 8 8 11 -1 -1 -1 -1 0 0 100 100 50 75 12 90 39 42 57 73 -2 -2 -2 -2
Sample Output
8 10000
数据太小了,直接暴力
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 5 using namespace std; 6 7 bool mp[105][105]; 8 9 int main() 10 { 11 int a,b,c,d; 12 memset(mp,0,sizeof(mp)); 13 while(scanf("%d %d %d %d",&a,&b,&c,&d)!=EOF) 14 { 15 // 每一组结束,输出并更新 16 if(a<0 || b<0 || c<0 || d<0) 17 { 18 int ans=0; 19 for(int i=0;i<=100;++i) 20 { 21 for(int j=0;j<=100;++j) 22 { 23 if(mp[i][j]) 24 { 25 ++ans; 26 } 27 } 28 } 29 printf("%d\n",ans); 30 memset(mp,0,sizeof(mp)); 31 continue; 32 } 33 // 暴力覆盖 34 if(a>c) 35 { 36 swap(a,c); 37 } 38 if(b>d) 39 { 40 swap(b,d); 41 } 42 for(int i=a;i<c;++i) 43 { 44 for(int j=b;j<d;++j) 45 { 46 mp[i][j]=true; 47 } 48 } 49 } 50 51 return 0; 52 }
标签:rap points div rect otherwise opp code content integer
原文地址:https://www.cnblogs.com/jishuren/p/12246027.html