hdu 1828 Picture 切割线求周长
Picture
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2144 Accepted Submission(s): 1139
Write a program to calculate the perimeter. An example with 7 rectangles is shown in Figure 1.
The corresponding boundary is the whole set of line segments drawn in Figure 2.
The vertices of all rectangles have integer coordinates.
0 <= number of rectangles < 5000
All coordinates are in the range [-10000,10000] and any existing rectangle has a positive area.
Please process to the end of file.
-15 0 5 10
-5 8 20 25
15 -4 24 14
0 -6 16 4
2 15 10 22
30 10 36 20
34 0 40 16
/*
统计周长
*/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define N 5003
#define hxl 10003
using namespace std; struct node
{
int begin;
int end;
int val;
int flag;
}Linex[N<<],Liney[N<<];
int Hash[]; bool cmp(node n1,node n2)
{
return n1.val<n2.val;
} int make_x(int NN)
{
int sum=,i,j;
for(i=;i<=NN;i++)
{
if(Linex[i].flag==)
{
for(j=Linex[i].begin;j<Linex[i].end;j++)
{
if(Hash[j]==)
sum++;
Hash[j]++;
}
}
else
{
for(j=Linex[i].begin;j<Linex[i].end;j++)
{
if(Hash[j]==)
sum++;
Hash[j]--;
} }
}
return sum;
} int make_y(int NN)
{
int sum=,i,j;
for(i=;i<=NN;i++)
{
if(Liney[i].flag==)
{
for(j=Liney[i].begin;j<Liney[i].end;j++)
{
if(Hash[j]==)
sum++;
Hash[j]++;
}
}
else
{
for(j=Liney[i].begin;j<Liney[i].end;j++)
{
if(Hash[j]==)
sum++;
Hash[j]--;
}
}
}
return sum;
} void make_ini(int NN)
{
int x1,y1,x2,y2,i,len=,sum=;
for(i=;i<=NN;i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1+=hxl;y1+=hxl;y2+=hxl;x2+=hxl; Linex[++len].val=x1;
Linex[len].begin=y1;
Linex[len].end=y2;
Linex[len].flag=; Liney[len].val=y1;
Liney[len].begin=x1;
Liney[len].end=x2;
Liney[len].flag=; Linex[++len].val=x2;
Linex[len].begin=y1;
Linex[len].end=y2;
Linex[len].flag=-; Liney[len].val=y2;
Liney[len].begin=x1;
Liney[len].end=x2;
Liney[len].flag=-;
}
sort(Linex+,Linex++len,cmp);
sort(Liney+,Liney++len,cmp);
memset(Hash,,sizeof(Hash));
sum+=make_x(len);
memset(Hash,,sizeof(Hash));
sum+=make_y(len);
printf("%d\n",sum);
} int main()
{
int NN;
while(scanf("%d",&NN)>)
{
make_ini(NN);
}
return ;
}
hdu 1828 Picture 切割线求周长的更多相关文章
- HDU 1828 Picture(长方形的周长和)
HDU 1828 Picture 题目链接 题意:给定n个矩形,输出矩形周长并 思路:利用线段树去维护,分别从4个方向扫一次,每次多一段的时候,就查询该段未被覆盖的区间长度,然后周长就加上这个长度,4 ...
- hdu 1828 线段树扫描线(周长)
Picture Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 1828 Picture(线段树扫描线求周长)
Picture Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- HDU 1828“Picture”(线段树+扫描线求矩形周长并)
传送门 •参考资料 [1]:算法总结:[线段树+扫描线]&矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) •题意 给你 n 个矩形,求矩形并的周长: •题解1(两次扫描线) 周 ...
- hdu 1828 Picture(线段树 || 普通hash标记)
http://acm.hdu.edu.cn/showproblem.php?pid=1828 Picture Time Limit: 6000/2000 MS (Java/Others) Mem ...
- HDU 1828 Picture (线段树+扫描线)(周长并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1828 给你n个矩形,让你求出总的周长. 类似面积并,面积并是扫描一次,周长并是扫描了两次,x轴一次,y ...
- 51nod 1206 && hdu 1828 Picture (扫描线+离散化+线段树 矩阵周长并)
1206 Picture 题目来源: IOI 1998 基准时间限制:2 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 收藏 关注 给出平面上的N个矩形(矩形的边平行于X轴 ...
- HDU 1828 Picture (线段树:扫描线周长)
依然是扫描线,只不过是求所有矩形覆盖之后形成的图形的周长. 容易发现,扫描线中的某一条横边对答案的贡献. 其实就是 加上/去掉这条边之前的答案 和 加上/去掉这条边之后的答案 之差的绝对值 然后横着竖 ...
- POJ 1177/HDU 1828 picture 线段树+离散化+扫描线 轮廓周长计算
求n个图矩形放下来,有的重合有些重合一部分有些没重合,求最后总的不规则图型的轮廓长度. 我的做法是对x进行一遍扫描线,再对y做一遍同样的扫描线,相加即可.因为最后的轮廓必定是由不重合的线段长度组成的, ...
随机推荐
- 将tomcat添加到服务中
转载自:http://blog.csdn.net/zjd934784273/article/details/47701011(windows) :http://www.cnblogs.com/ilah ...
- 程序媛计划——mysql连接表
#inner join等值连接/内连接 mysql> select * from info; +------+-------------+----------+ | name | phone | ...
- if判断和switch case 和三元运算符整理
if判断和switch case 和三元运算符整理 例子1:if判断写法: <script type="text/javascript"> var num = 12; ...
- Mysql分析-profile详解
一.前言当我们要对某一条sql的性能进行分析时,可以使用它. Profiling是从 mysql5.0.3版本以后才开放的.启动profile之后,所有查询包括错误的语句都会记录在内.关闭会话或者se ...
- [HTML] H5在webApp中的注意事项
常用的meta标签 <!--防止手机中网页放大和缩小--> <meta name="viewport" content="width=device-wi ...
- Python小白学习之路(四)——第一次练习题
写在前面: 今天下雪了呢!连着两天都没有更新学习记录. 我没有偷懒呢.做了一天的练习题,昨天学的内容还没总结完,太累了就回去睡觉了 连续一周早起,强大的内心也无法支撑我疲惫的身体 今天早起做了整理.加 ...
- 用Python玩转数据——第五周数据统计和可视化
一.数据获取 1.本地数据 with 语句,pd.read_csv('data.csv') 2.网站上数据 2.1 直接获取网页源码,在用正则表达式进行删选 2.2 API接口获取---以豆瓣为例 i ...
- java命令行编译和运行引用jar包的文件
经常遇到需要添加第三方jar文件的情况.在命令行状态下要加载外部的jar文件非常麻烦,很不好搞,在网上折腾了很久终于搞定了,在这里做个笔记: 2.运行:java -Djava.ext.dirs=./l ...
- Hadoop简介与伪分布式搭建—DAY01
一. Hadoop的一些相关概念及思想 1.hadoop的核心组成: (1)hdfs分布式文件系统 (2)mapreduce 分布式批处理运算框架 (3)yarn 分布式资源调度系统 2.hadoo ...
- Hadoop2.0.0+CDH4.5.0集群配置
Hadoop 2.0.0-cdh4.5.0安装:http://blog.csdn.net/u010967382/article/details/18402217 CDH版本下载:http://arch ...