描述
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. VSFTP 服务器配置

    解决root用户无法登陆ftp传输文件的问题 配置vsftpd用户,启用root用户.  #cd /etc/vsftpd #vi ftpusers  注释掉root  修改user_list文件  # ...

  2. touch修改文件时间戳

    https://blog.csdn.net/lsbhjshyn/article/details/51443304 touch -t 20181011000.01 text.txt

  3. python模块sys

    #!/bin/env python #-*- encoding=utf8 -*- import sys if __name__=="__main__": # 在解释器启动后, ar ...

  4. oracle归档日志关闭和打开

    查询归档日志状态 方法一 SQL> archive log list; 方法二 SQL> select name,log_mode from V$database; 打开归档日志 orac ...

  5. [C语言]数据类型与计算

    ------------------------------------------------------------------------------------------------- 实际 ...

  6. 23.网络.md

    目录 1.基本概念 2.常用函数 3.端口 4.协议 4.1.2代码步骤 4.1.3UDPDemo 4.1.4通信格式 4.1.5 群发Demo: 4.1.6丢失数据的情况 4.2TCP 4.2.1三 ...

  7. Working with the Dynamic Type in C#

    Working with the Dynamic Type in C# https://www.red-gate.com/simple-talk/dotnet/c-programming/workin ...

  8. List of numerical libraries,Top Numerical Libraries For C#

    Top Numerical Libraries For C# AlgLib (http://alglib.net) ALGLIB is a numerical analysis and data pr ...

  9. 解决运行wamp提示“MSVCR110.dll”丢失的问题!

    我在Windows系统上安装wampserver2.5 64位,安装到最后,总是提示丢失msvcr110.dll 解决办法: 到这个网站下载一个Visual C++ Redistributable f ...

  10. MOSS 2007 错误0x80040E14解决

    今天公司内网莫名的出现错误,只能新建列表条目,不能创建网站,到后来列表条目也不能创建了,一直报0x80040E14错误.于是Google一把,搜索这个错误号,然后在apearce 的Blog找到了原因 ...