【IOI1999】HDU1828 Picture
来源:互联网 发布:鬼泣3 但丁觉醒 mac版 编辑:程序博客网 时间:2024/06/10 07:55
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.
和求面积并【poj1151 Atlantis】很类似。
分别沿x轴和y轴扫描,每次统计与当前轴垂直的轴上的长度,具体就是这一次的总长度-上一次的总长度。
poj的数据比较弱,hdu的数据强。注意考虑重边,要先加再减。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxm=10000;struct seg{ int x,y1,y2,k; bool operator < (const seg &ss) const { return x<ss.x||(x==ss.x&&k>ss.k); }}a[100010],b[100010];int abs(int x){ return x>0?x:-x;}int n,cov[1000010],tot,m,sum[1000010];void mark(int p,int L,int R,int l,int r,int k){ if (L==l&&R==r) { cov[p]+=k; if (cov[p]) sum[p]=R-L+1; else sum[p]=sum[p*2]+sum[p*2+1]; return; } int M=(L+R)/2; if (r<=M) mark(p*2,L,M,l,r,k); else { if (l>M) mark(p*2+1,M+1,R,l,r,k); else { mark(p*2,L,M,l,M,k); mark(p*2+1,M+1,R,M+1,r,k); } } if (cov[p]) sum[p]=R-L+1; else sum[p]=sum[p*2]+sum[p*2+1];}int main(){ int i,j,k,p,q,x,y,z,K=0,x1,x2,y1,y2,last,ans; while (scanf("%d",&n)==1) { for (i=1;i<=n;i++) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); x1+=maxm; x2+=maxm; y1+=maxm; y2+=maxm; a[2*i-1]=(seg){x1,y1,y2,1}; a[2*i]=(seg){x2,y1,y2,-1}; b[2*i-1]=(seg){y1,x1,x2,1}; b[i*2]=(seg){y2,x1,x2,-1}; } ans=0; sort(a+1,a+2*n+1); last=0; memset(sum,0,sizeof(sum)); memset(cov,0,sizeof(cov)); for (i=1;i<=2*n;i++) { mark(1,1,2*maxm,a[i].y1+1,a[i].y2,a[i].k); ans+=abs(sum[1]-last); last=sum[1]; } sort(b+1,b+2*n+1); last=0; memset(sum,0,sizeof(sum)); memset(cov,0,sizeof(cov)); for (i=1;i<=2*n;i++) { mark(1,1,2*maxm,b[i].y1+1,b[i].y2,b[i].k); ans+=abs(sum[1]-last); last=sum[1]; } printf("%d\n",ans);}}
- 【IOI1999】HDU1828 Picture
- HDU1828--Picture
- hdu1828 Picture
- hdu1828 Picture
- HDU1828-Picture
- hdu1828 Picture 扫描线
- 线段树 hdu1828 Picture
- [题解]hdu1828 Picture
- HDU1828 Picture 周长并 线扫描
- 【HDU1828】Picture【线段树】【矩形周长并】
- POJ1177 HDU1828 Picture,线段树求矩形并周长
- hdu1828 Picture(扫描线+矩形周长并+线段树)
- 扫描线 求多个矩形合并后的周长 hdu1828 Picture
- hdu1828 Picture (线段树+扫描线)(求周长并)
- HDU1828 Picture(线段树+扫描线求周长并)
- hdu1828 Picture (矩形周长并+扫描线)
- hdu1828 Picture--扫描线 & 周长并(待解决)
- POJ 1177&&HDU1828 Picture 线段树+扫描线
- 移动端不同分辨率手机的适配问题
- 理解 Thread.Sleep 函数
- c
- GetLastError
- c语言libcurl库的异步用法
- 【IOI1999】HDU1828 Picture
- linux系统性能监控--I/O利用率
- 如何在Linux(CentOS 7)命令行模式安装VMware Tools
- PHP实现简单的验证码功能机制
- SDK Manager里找不到API安装的选项怎么办?不翻墙解决SDK manager下载问题
- php:快递API接口无限制免费
- LeetCode OJ-41-First Missing Positive
- JDK、JRE、JVM三者间的关系
- idea使用教程