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. day85 ModuleForm Form组件

    1 forms组件与modelform组件 forms组件: https://www.cnblogs.com/yuanchenqi/articles/9036474.htmlmodelForm组件:h ...

  2. 删除 iptables nat 规则

    原文:https://www.cnblogs.com/hixiaowei/p/8954161.html 删除FORWARD 规则: iptables -nL FORWARD --line-number ...

  3. Python 将一个列表里面的元素拼接成一个字符串

    item1 = ["lowman", "isbusy"] item2 = ",".join(item1) # 根据实际需要使用相应的分隔符连 ...

  4. nginx代理websocket协议

    以下是代码段.location /wsapp/ {     proxy_pass http://wsbackend;     proxy_http_version 1.1;     proxy_set ...

  5. python-xlwt给excel添加样式

    #coding:utf-8import osimport time        import xlwt filename="test_xlwt.xls"if os.path.ex ...

  6. python操作oracle数据库-查询

    python操作oracle数据库-查询 参照文档 http://www.oracle.com/technetwork/cn/articles/dsl/mastering-oracle-python- ...

  7. P1494 小Z的袜子

    P1494 小Z的袜子 莫队板子题,对询问进行排序+分块,从而得到巧妙的复杂度 对于L,R的询问. 设其中颜色为x,y,z的袜子的个数为a,b,c... 那么答案即为 (a*(a-1)/2+b*(b- ...

  8. 【xsy3423】党² 线段树+李超线段树or动态半平面交

    本来并不打算出原创题的,此题集CF542A和sk的灵感而成,算个半原创吧. 题目大意: 给定有$n$个元素的集合$P$,其中第$i$个元素中包含$L_i,R_i,V_i$三个值. 给定另一个有$n$个 ...

  9. HTML BODY 背景图片

    内嵌: background:url(背景图片路径)  no-repeat;/*不重复默认在左上方*/ background:url(背景图片路径)  no-repeat center;/*不重复背景 ...

  10. Office自动生成目录步骤(非常实用)(图文详解)

    不多说,直接上干货! 结束 欢迎大家,加入我的微信公众号:大数据躺过的坑        人工智能躺过的坑       同时,大家可以关注我的个人博客:    http://www.cnblogs.co ...