描述
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.

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
题意
给你N个矩形,每个矩形给你左下和右上端点,求周长并
题解
很容易想到的就是离散化后,先扫一遍x,再扫一遍y
每次加上这次和上次的差即为新加线段的长度
代码
 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int N=;
int col[][N<<],sum[][N<<],x[][N<<];
struct seg
{
int l,r,h,s;
seg() {}
seg(int l,int r,int h,int s):l(l),r(r),h(h),s(s) {}
bool operator<(const seg &ob)const
{
return h<ob.h;
}
}s[][N<<];
void PushUp(int rt,int l,int r,int flag)
{
if(col[flag][rt])sum[flag][rt]=x[flag][r+]-x[flag][l];
else if(l==r)sum[flag][rt]=;
else sum[flag][rt]=sum[flag][rt<<]+sum[flag][rt<<|];
}
void Update(int L,int R,int flag,int C,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
col[flag][rt]+=C;
PushUp(rt,l,r,flag);
return;
}
int mid=(l+r)>>;
if(L<=mid)Update(L,R,flag,C,l,mid,rt<<);
if(R>mid)Update(L,R,flag,C,mid+,r,rt<<|);
PushUp(rt,l,r,flag);
}
int main()
{
int n,x1,x2,y1,y2;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<n;i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
s[][i]=seg(x1,x2,y1,);
x[][i]=x1;
s[][n+i]=seg(x1,x2,y2,-);
x[][n+i]=x2; s[][i]=seg(y1,y2,x1,);
x[][i]=y1;
s[][n+i]=seg(y1,y2,x2,-);
x[][n+i]=y2;
}
n<<=;
sort(x[],x[]+n);
sort(s[],s[]+n);
sort(x[],x[]+n);
sort(s[],s[]+n);
int ans=,pre=,pre1=;
for(int i=;i<n;i++)
{
int l=lower_bound(x[],x[]+n,s[][i].l)-x[];
int r=lower_bound(x[],x[]+n,s[][i].r)-x[]-;
Update(l,r,,s[][i].s,,n-,);
ans+=abs(sum[][]-pre);
pre=sum[][];
}
for(int i=;i<n;i++)
{
int l=lower_bound(x[],x[]+n,s[][i].l)-x[];
int r=lower_bound(x[],x[]+n,s[][i].r)-x[]-;
Update(l,r,,s[][i].s,,n-,);
ans+=abs(sum[][]-pre1);
pre1=sum[][];
}
printf("%d\n",ans);
}
return ;
}

POJ 1177 Picture(线段树周长并)的更多相关文章

  1. HDU 1828 / POJ 1177 Picture --线段树求矩形周长并

    题意:给n个矩形,求矩形周长并 解法:跟求矩形面积并差不多,不过线段树节点记录的为: len: 此区间线段长度 cover: 此区间是否被整个覆盖 lmark,rmark: 此区间左右端点是否被覆盖 ...

  2. POJ 1177 Picture(线段树 扫描线 离散化 求矩形并面积)

    题目原网址:http://poj.org/problem?id=1177 题目中文翻译: 解题思路: 总体思路: 1.沿X轴离散化建树 2.按Y值从小到大排序平行与X轴的边,然后顺序处理 如果遇到矩形 ...

  3. poj 1177 Picture (线段树 扫描线 离散化 矩形周长并)

    题目链接 题意:给出n个矩形,每个矩形给左下 和 右上的坐标,求围成的周长的长度. 分析: 首先感谢大神的博客,最近做题经常看大神的博客:http://www.cnblogs.com/kuangbin ...

  4. poj 1177 --- Picture(线段树+扫描线 求矩形并的周长)

    题目链接 Description A number of rectangular posters, photographs and other pictures of the same shape a ...

  5. Picture POJ - 1177 (线段树-扫描线)

    A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wa ...

  6. POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)

    POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...

  7. Buy Tickets POJ - 2828 思维+线段树

    Buy Tickets POJ - 2828 思维+线段树 题意 是说有n个人买票,但是呢这n个人都会去插队,问最后的队列是什么情况.插队的输入是两个数,第一个是前面有多少人,第二个是这个人的编号,最 ...

  8. POJ 1177 Picture(线段树:扫描线求轮廓周长)

    题目链接:http://poj.org/problem?id=1177 题目大意:若干个矩形,求这些矩形重叠形成的图形的轮廓周长. 解题思路:这里引用一下大牛的思路:kuangbin 总体思路: 1. ...

  9. HDU 1828 / POJ 1177 Picture (线段树扫描线,求矩阵并的周长,经典题)

    做这道题之前,建议先做POJ 1151  Atlantis,经典的扫描线求矩阵的面积并 参考连接: http://www.cnblogs.com/scau20110726/archive/2013/0 ...

随机推荐

  1. WPF 透明窗体

    窗体属性中设置:Background="Transparent" AllowsTransparency="True" WindowStyle="Non ...

  2. LInux 阿里云系统遇到挖矿程序

    参考 https://blog.csdn.net/qq_37837029/article/details/82314428 重要的一点,移除下面文件里面的定时任务 /var/spool/cron/cr ...

  3. datasnap服务器支持的参数类型

    可作为参数的类型TDBXWideStringValueTDBXAnsiStringValueTDBXInt16ValueTDBXInt32ValueTDBXInt64ValueTDBXSingleVa ...

  4. C++复习:对C的拓展

    简单的C++程序 求圆的周长和面积 数据描述:             半径,周长,面积均用实型数表示 数据处理:         输入半径 r:         计算周长 = 2*π*r :     ...

  5. C语言复习: 二级指针和多级指针

    二级指针内存模型建立 void main2() {     int i = 0;       //指针数组     char * p1[] = { "123", "456 ...

  6. 手工获取AWR报告

    AWR(Automatic Workload Repository)报告常用于Oracle数据库性能分析.熟练解读AWR报告有助于快速分析Oracle性能问题.下面主要描述如何手工获取AWR报告. 操 ...

  7. [福大2018高级软工教学]团队Beta阶段成绩汇总

    一.作业地址: https://edu.cnblogs.com/campus/fzu/AdvancedSoftwareEngineerning2018/homework/2465 二.Beta阶段作业 ...

  8. web前端基础知识!

    [HTML文档的基本结构和语法][基本结构]: <HTML> HTML 文件开始 <HEAD> HTML 文件的头部开始 <title> 网页的标题</tit ...

  9. C#关键字as出现的错误

    ObjectCache cache = MemoryCache.Default; string cacheData1 = cache["key1"] as string;//得不到 ...

  10. 吴裕雄 19-Mysql 连接的使用

    JOIN 按照功能大致分为如下三类:INNER JOIN(内连接,或等值连接):获取两个表中字段匹配关系的记录.LEFT JOIN(左连接):获取左表所有记录,即使右表没有对应匹配的记录.RIGHT ...