Picture

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2144    Accepted Submission(s): 1139

Problem Description
A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wall. Their sides are all vertical or horizontal. Each rectangle can be partially or totally covered by the others. The length of the boundary of the union of all rectangles is called the perimeter.

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.

 
Input
Your program is to read from standard input. The first line contains the number of rectangles pasted on the wall. In each of the subsequent lines, one can find the integer coordinates of the lower left vertex and the upper right vertex of each rectangle. The values of those coordinates are given as ordered pairs consisting of an x-coordinate followed by a y-coordinate.

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.

 
Output
Your program is to write to standard output. The output must contain a single line with a non-negative integer which corresponds to the perimeter for the input rectangles.
 
Sample Input
 
7
-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
 
Sample Output
228
 
/*
统计周长
*/ #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 切割线求周长的更多相关文章

  1. HDU 1828 Picture(长方形的周长和)

    HDU 1828 Picture 题目链接 题意:给定n个矩形,输出矩形周长并 思路:利用线段树去维护,分别从4个方向扫一次,每次多一段的时候,就查询该段未被覆盖的区间长度,然后周长就加上这个长度,4 ...

  2. hdu 1828 线段树扫描线(周长)

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  3. HDU 1828 Picture(线段树扫描线求周长)

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  4. HDU 1828“Picture”(线段树+扫描线求矩形周长并)

    传送门 •参考资料 [1]:算法总结:[线段树+扫描线]&矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) •题意 给你 n 个矩形,求矩形并的周长: •题解1(两次扫描线) 周 ...

  5. hdu 1828 Picture(线段树 || 普通hash标记)

    http://acm.hdu.edu.cn/showproblem.php?pid=1828 Picture Time Limit: 6000/2000 MS (Java/Others)    Mem ...

  6. HDU 1828 Picture (线段树+扫描线)(周长并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1828 给你n个矩形,让你求出总的周长. 类似面积并,面积并是扫描一次,周长并是扫描了两次,x轴一次,y ...

  7. 51nod 1206 && hdu 1828 Picture (扫描线+离散化+线段树 矩阵周长并)

    1206 Picture  题目来源: IOI 1998 基准时间限制:2 秒 空间限制:131072 KB 分值: 160 难度:6级算法题  收藏  关注 给出平面上的N个矩形(矩形的边平行于X轴 ...

  8. HDU 1828 Picture (线段树:扫描线周长)

    依然是扫描线,只不过是求所有矩形覆盖之后形成的图形的周长. 容易发现,扫描线中的某一条横边对答案的贡献. 其实就是 加上/去掉这条边之前的答案 和 加上/去掉这条边之后的答案 之差的绝对值 然后横着竖 ...

  9. POJ 1177/HDU 1828 picture 线段树+离散化+扫描线 轮廓周长计算

    求n个图矩形放下来,有的重合有些重合一部分有些没重合,求最后总的不规则图型的轮廓长度. 我的做法是对x进行一遍扫描线,再对y做一遍同样的扫描线,相加即可.因为最后的轮廓必定是由不重合的线段长度组成的, ...

随机推荐

  1. git install

    wget -O git-master.zip https://codeload.github.com/git/git/zip/master unzip git-master.zip cd git-ma ...

  2. falcon nodata 小坑一枚

    按照官方文档配置完一切正常,唯独 nodata, 明明有正常的数据,但是为什么 nodata 会认为是没收到呢 困扰许久,直到看了数据库中的数据才恍然大悟 falcon_portal库中的 hosts ...

  3. sublime text3---Emmet:HTML/CSS代码快速编写神器

    Emmet的前身是大名鼎鼎的Zen coding,如果你从事Web前端开发的话,对该插件一定不会陌生.它使用仿CSS选择器的语法来生成代码,大大提高了HTML/CSS代码编写的速度,比如下面的演示: ...

  4. 【xsy1018】 小A的字母游戏 扩展CRT

    题目大意:有$n$个无限长的循环字符串,所谓循环字符串,就是由某一个子串重复叠加而成.现在想知道最早在哪一位,这n个字符串的那一位的字母相同. 数据范围:$n≤30000$,答案$<2^{63} ...

  5. JavaScript 函数定义方法

    JavaScript 函数定义方法. 函数声明 在之前的教程中,你已经了解了函数声明的语法 : function functionName(parameters) { 执行的代码 } 函数声明后不会立 ...

  6. Linux 上安装 Couchbase服务

    down: http://www.couchbase.com/downloads/ doc:  http://docs.couchbase.com/archive-index/ forums: htt ...

  7. 【优化】Filddler用于移动端

    Fiddler是一个非常强大的Web调试工具,它能捕获所有客户端和服务器的http和https请求,我们可以对请求监视.设置断点,也能修改输入输出数据,这些特性使得Fiddler成为广大web开发者的 ...

  8. SPSS学习系列之SPSS Modeler怎么修改默认的内存大小(图文详解)

    不多说,直接上干货! 问题来源: 如果你的电脑内存配置比较低的话,会随着数据量增加(尤其是大数据),带不起的情况很有可能发生,会出现一些内存报错... ... 解决办法: 打开“工具”,在modele ...

  9. 关于Class的invokeDynamic指令

    (1)java7之Special Methods (2)invokedynamic指令 https://www.cnblogs.com/wade-luffy/p/6058087.html public ...

  10. android 解决studio生成aar包并在其他工程引用aar包的坑,不需要任何gradle配置

    1.首先我们创建一个module 2.编写我们的一个类 3.编译我们的module,生成release版本的aar,注意千万不要是debug版本的, 点击最右边的gradle面板,选择我们的modul ...