HDU 1264 Counting Squares(模拟)
2016-02-09 15:55
316 查看
题目链接
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
Your output should be the number of squares covered by each set of rectangles. Each number should be printed on a separate line.
[align=left]Sample Input[/align]
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
[align=left]Sample Output[/align]
8
10000
题解:水题,因为数字范围不大,可以用二维数组保存每个1x1的块是否被访问过。
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
Your output should be the number of squares covered by each set of rectangles. Each number should be printed on a separate line.
[align=left]Sample Input[/align]
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
[align=left]Sample Output[/align]
8
10000
题解:水题,因为数字范围不大,可以用二维数组保存每个1x1的块是否被访问过。
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <cstring> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <map> #define PI acos(-1.0) #define ms(a) memset(a,0,sizeof(a)) #define msp memset(mp,0,sizeof(mp)) #define msv memset(vis,0,sizeof(vis)) using namespace std; //#define LOCAL int mp[120][120]; int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL ios::sync_with_stdio(false); int x1,y1,x2,y2; int cnt=0; msp; while(cin>>x1>>y1>>x2>>y2) { if(x1==-1){printf("%d\n",cnt); msp,cnt=0;} if(x1==-2){ printf("%d\n",cnt);break;} if(x1>x2)swap(x1,x2); if(y1>y2)swap(y1,y2); for(int i=x1;i<x2;i++) for(int j=y1;j<y2;j++) if(mp[i][j])continue; else {cnt++,mp[i][j]=1;} } return 0; }
相关文章推荐
- google推出的SwipeRefreshLayout下拉刷新用法
- epoll example
- 构建Linux内核驱动demo子系统示例
- PHP - json生成与转换
- 5.4、聚类之EM聚类实例
- Java认证考试实例疑难辨析(2)
- 同余式运算的总结
- 360Wifi2代在linux上安装使用 踩过的的坑和成功的途径 分享一下
- JSP学习小结
- 断开式连接批量更新数据库数据(grid编辑)
- jetbrains
- HDU 3452 Bonsai
- [PHP]如何在百度(BAE)和新浪(SAE)的云平台使用PHP连接MySQL并返回结果数据
- 如何划分子网
- 【慕课笔记】U3 继承 第6节 JAVA中的Object类(一)
- 之后一段时间的安排
- springmvc(十七)springmvc注解开发-validation校验-商品修改校验
- 4. AJAX 省市联动
- HTML+CSS笔记 CSS入门续集
- JavaScript DOM编程基础精华01(DOM入门,DOM模型和获取页面元素,事件,window对象的方法)