Counting Squares[HDU1264]
Counting Squares
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1072 Accepted Submission(s): 529
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.
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 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
Source
浙江工业大学第四届大学生程序设计竞赛
Recommend
JGShining
漂浮法的简单应用
#include<stdio.h>
int l[],r[],u[],d[],N,ans;
void dfs(int ll,int rr,int uu,int dd,int dep)
{
if (dep==N)
{
ans+=(rr-ll)*(uu-dd);
return;
}
if (ll==rr || uu==dd) return;
if (rr<=l[dep+] || r[dep+]<=ll || u[dep+]<=dd || uu<=d[dep+]) dfs(ll,rr,uu,dd,dep+);
else
{
if (ll<l[dep+] && l[dep+]<rr)
{
dfs(ll,l[dep+],uu,dd,dep+);
ll=l[dep+];
}
if (ll<r[dep+] && r[dep+]<rr)
{
dfs(r[dep+],rr,uu,dd,dep+);
rr=r[dep+];
}
if (dd<u[dep+] && u[dep+]<uu)
{
dfs(ll,rr,uu,u[dep+],dep+);
uu=u[dep+];
}
if (dd<d[dep+] && d[dep+]<uu)
{
dfs(ll,rr,d[dep+],dd,dep+);
dd=d[dep+];
}
}
}
int main()
{
while (true)
{
N=;
int xx1,xx2,yy1,yy2,i;
while (scanf("%d%d%d%d",&xx1,&yy1,&xx2,&yy2)!=EOF)
{
N++;
if (xx1<xx2)
{
l[N]=xx1;
r[N]=xx2;
}
else
{
l[N]=xx2;
r[N]=xx1;
}
if (yy1<yy2)
{
u[N]=yy2;
d[N]=yy1;
}
else
{
u[N]=yy1;
d[N]=yy2;
}
if (xx1<)
{
N--;
break;
}
}
ans=;
for (i=;i<=N;i++) dfs(l[i],r[i],u[i],d[i],i);
printf("%d\n",ans);
if (xx1==-) return ;
}
return ;
}
Counting Squares[HDU1264]的更多相关文章
- HDU 1264 Counting Squares(线段树求面积的并)
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)
版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...
- HDU 1264 Counting Squares(模拟)
题目链接 Problem Description Your input is a series of rectangles, one per line. Each rectangle is speci ...
- D - Counting Squares
Your input is a series of rectangles, one per line. Each rectangle is specified as two points(X,Y) t ...
- Counting Squares_hdu_1264(矩阵).java
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- tc 146 2 RectangularGrid(数学推导)
SRM 146 2 500RectangularGrid Problem Statement Given the width and height of a rectangular grid, ret ...
- UVaLive 6602 Counting Lattice Squares (找规律)
题意:给定一个n*m的矩阵,问你里面有几面积为奇数的正方形. 析:首先能知道的是,大的矩阵是包括小的矩阵的,而且面积为奇数,我们只要考虑恰好在边界上的正方形即可,画几个看看就知道了,如果是3*3的有3 ...
- UVALive 6602 Counting Lattice Squares
给定一个n*m的网格,求面积为奇数的正方形有多少个. 首先是n*m个面积为1的,然后剩下的要么是边长为奇数,要么被这样一个奇数边长所包围. 原因如下: 对于一个边长不平行于坐标抽的正方形,其边长一定是 ...
- POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)
来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536 ...
随机推荐
- [素材资源] Android开发性能优化简介(非常不错的)
转自(http://www.starming.com/index.php?action=plugin&v=wave&tpl=union&ac=viewgrouppost& ...
- ecshop设置一个子类对应多个父类并指定跳转url的修改方法
这是一篇记录在日记里面的技术文档,其实是对ecshop的二次开发.主要作用是将一个子类对应多个父类,并指定条跳转url的功能.ecshop是一款在线购物网站,感兴趣的可以下载源码看看.我们看看具体是怎 ...
- hdu2089
基本的数位dp #include <cstdio> #include <cstring> using namespace std; #define D(x) x ; int n ...
- Hadoop入门程序WordCount的执行过程
首先编写WordCount.java源文件,分别通过map和reduce方法统计文本中每个单词出现的次数,然后按照字母的顺序排列输出, Map过程首先是多个map并行提取多个句子里面的单词然后分别列出 ...
- Java for LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Java for LeetCode 149 Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- CodeForces - 405C
Unusual Product Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- MFC dfs遍历文件
//如果涉及到大文件的遍历(大于4GB),可以将以下代码_finddata_t换成__finddata64_t,_findfirst换成_findfirst64,_findnext换成_findnex ...
- 一台机器开2个Tomcat修改端口号
修改一个Tomcat端口号步骤:1.找到Tomcat目录下的conf文件夹2.进入conf文件夹里面找到server.xml文件3.打开server.xml文件4.在server.xml文件里面找到下 ...
- fedora 添加其他操作系统到 GRUB 2 菜单
# yum install os-prober # grub2-mkconfig -o /boot/grub2/grub.cfg