Counting Squares
来源:互联网 发布:java 算术运算符 编辑:程序博客网 时间:2024/05/21 06:42
Counting Squares
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 6 Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Your input is a series of rectangles, one per line. Each rectangle is specified as two points(X,Y) that specify the opposite corners of a rectangle. All coordinates will be integers in the range 0 to 100. For example, the line
5 8 7 10
specifies the rectangle who's corners are(5,8),(7,8),(7,10),(5,10).
If drawn on graph paper, that rectangle would cover four squares. Your job is to count the number of unit(i.e.,1*1) squares that are covered by any one of the rectangles given as input. Any square covered by more than one rectangle should only be counted once.
5 8 7 10
specifies the rectangle who's corners are(5,8),(7,8),(7,10),(5,10).
If drawn on graph paper, that rectangle would cover four squares. Your job is to count the number of unit(i.e.,1*1) squares that are covered by any one of the rectangles given as input. Any square covered by more than one rectangle should only be counted once.
Input
The 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.
Output
Your 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 106 9 7 86 8 8 11-1 -1 -1 -10 0 100 10050 75 12 9039 42 57 73-2 -2 -2 -2
Sample Output
810000#include<stdio.h>#include<string.h>#include<stdlib.h>#define N 105int ax,bx,ay,by,a;bool xy[N][N];int i,j,cover;int main(){ while(~scanf("%d%d%d%d",&ax,&ay,&bx,&by)) { if(ax==ay&&ax==bx&&ax==by&&(ax==-1||ax==-2)) { for(i=0,cover=0;i<N;i++) for(j=0;j<N;j++) cover+=xy[i][j]; printf("%d\n",cover); if(ax==-2) break; memset(xy,0,sizeof(xy)); } else { if(ax>bx) {a=ax;ax=bx;bx=a;} if(ay>by) {a=ay;ay=by;by=a;} for(i=ax;i<bx;i++) for(j=ay;j<by;j++) xy[i][j]=1; } } system("pause"); return 0;}
- Counting Squares
- HDU 1264 Counting Squares
- HDU 1264 Counting Squares
- hdu1264 Counting Squares
- hdu 1256 Counting Squares
- HDU 1264 Counting Squares
- hdu 1264 Counting Squares
- HDU 1264 Counting Squares
- Counting Squares(1264)
- HDU 1264 Counting Squares
- 1264:Counting Squares
- hdu1264 Counting Squares
- hdu 1264 Counting Squares
- UVALive 6602 Counting Lattice Squares
- hdu1246 Counting Squares(暴力hash)
- hdu 1264 counting the squares
- ZOJ 3107 Counting Squares//计算几何
- hdu 1264 Counting Squares(扫描线)
- 归并排序算法(C#实现)
- UVA 714 Copying Books 最大值最小化问题 (贪心 + 二分)
- 编程小技巧
- 冒泡排序算法(C#实现)
- process 0
- Counting Squares
- Lecture 4 (中)
- 快速排序算法(C#实现)
- Lecture 4(下)
- web.xml中部署servlet注意
- ViewController的使用及生命周期
- POJ 3254 Corn Fields (状态压缩DP)
- Cuts the cake
- 快逸V5设置两表关联