HDU 1264 Counting Squares
来源:互联网 发布:51信用卡待遇 知乎 编辑:程序博客网 时间:2024/06/05 01:00
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
直接hash即可。
#include<iostream> #include<algorithm>#include<cstdio>#include<cstring>#include<string>using namespace std;const int maxn = 101;int x1, x2, Y1, Y2, f[maxn*maxn] = { 0 };int find(){int tot = 0;for (int i = 0; i < maxn*maxn; f[i] = 0, i++) tot += f[i];return tot;}int main(){while (~scanf("%d%d%d%d", &x1, &Y1, &x2, &Y2)){if (x1 < 0) { cout << find() << endl; continue; }for (int i = min(x1, x2); max(x1, x2) - i; i++)for (int j = min(Y1, Y2); max(Y1, Y2) - j; j++)f[i*maxn + j] = 1;}return 0;}
0 0
- HDU 1264 Counting Squares
- HDU 1264 Counting Squares
- HDU 1264 Counting Squares
- hdu 1264 Counting Squares
- HDU 1264 Counting Squares
- HDU 1264 Counting Squares
- hdu 1264 Counting Squares
- hdu 1264 counting the squares
- hdu 1264 Counting Squares(扫描线)
- hdu 1256 Counting Squares
- Counting Squares(1264)
- 1264:Counting Squares
- HDU 1264 Counting Squares(哈希表||离散化)
- HDU-1264 Counting Squares(矩形面积并模板)
- HDU 1264 Counting Squares(线段树+面积并)
- Counting Squares
- HDU-1264 Counting Squares 矩形面积并 线段树+扫描线
- HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)
- 求职应聘C++复习小结
- 在Android模拟器中部署apk文件
- Oracle 多行函数
- 实时调度之FIFO
- LeetCode 45.Jump Game II
- HDU 1264 Counting Squares
- 寒城攻略:Listo 教你 25 天学会 Swift 语言 - 08 Functions
- Swift UI专项训练7 数据添加
- 前端跨域杂谈
- 5款替代微软Visio的开源免费软件
- SpringMVC中的XXE漏洞测试
- Feekood脚本语言概述
- 关于hibernate的缓存使用
- html+css实现图片转动