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 ...
随机推荐
- 查看远程git log
$ git reset --hard bit/add $ git log --oneline --graph
- session 实现登录功能注意事项
php5之后废除了session_unregister()函数,可以用 session_destory().其他的也都没有啥了,还有就是输出嵌入的PHP代码用=代码见我的git:https://git ...
- [POJ1050]To the Max
[POJ1050]To the Max 试题描述 Given a two-dimensional array of positive and negative integers, a sub-rect ...
- c# 继承,多态,new /overrid 区别, 引用父类的方法
好久没碰c#了,偶尔需要制作点小工具.为了一个灵活的架构设计,需要对继承/多态有比较深刻的理解. 不料忘得差不多了,好吧,再来回忆下.直接上代码了,如下: using System; using Sy ...
- Shell编程基础
写之前我们先来搞清楚为什么要学shell,学习要有目的性shell简单.灵活.高效,特别适合处理一些系统管理方面的小问题shell可以实现自动化管理,让系统管理员的工作变得容易.简单.高效shell脚 ...
- tomcat启动是报Multiple Contexts have a path of "/XXX"
Eclipse集成了tomcat,启动时报如下异常: Could not publish server configuration for Tomcat v7.0 Server at localhos ...
- linux下搭建svn版本控制软件
svn作为曾经流行的版本控制控制软件,它优异的版本控制功能在有意无意间已经深入IT人的工作了.然而虽然有后起之秀的git,但现在使用svn的项目并不在少数.最近有个项目需要协同开发,由于对svn用得比 ...
- hdu 1098 Lowest Bit 解题报告
题目链接:http://code.hdu.edu.cn/game/entry/problem/show.php?chapterid=1§ionid=2&problemid=22 ...
- 局域网通过ip查mac地址、通过mac地址查ip方法
sh-4.1# which arp #linux主机A /sbin/arp sh-4.1# arp -a 192.168.1.10 #主机B的IP bogon (:8t:8p::: [ether] o ...
- unix PS命令和JPS命令的区别
1.JPS介绍 用来查看基于HotSpot的JVM里面中,所有具有访问权限的Java进程的具体状态, 包括进程ID,进程启动的路径及启动参数等等,与unix上的ps类似,只不过jps是用来显示java ...