HDOJ 题目1828 Picture (线段树+扫描线)
来源:互联网 发布:omnigraffle 网络模板 编辑:程序博客网 时间:2024/05/24 07:10
Picture
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3646 Accepted Submission(s): 1884
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.
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.
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 2515 -4 24 140 -6 16 42 15 10 2230 10 36 2034 0 40 16
Sample Output
228
Source
IOI 1998
Recommend
linle | We have carefully selected several similar problems for you: 2871 1823 3016 1543 3458
求矩形周长并
ac代码
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<algorithm> #include<math.h>#define N 25010 #define INF 0x3f3f3f3f#define min(a,b) (a>b?b:a)#define max(a,b) (a>b?a:b)using namespace std; struct s { double x1,x2,y; int flag; }a[N<<2]; double __hash[N<<2],sum[N<<2]; int col[N<<2],lb[N<<2],rb[N<<2],num[N<<2]; int cmp(s a,s b) { return a.y<b.y; } int bseach(double key,int n) { int l=1,r=n; while(l<=r) { int mid=(l+r)>>1; if(__hash[mid]==key) return mid; if(__hash[mid]<key) l=mid+1; else r=mid-1; } return l; }void build(int l,int r,int tr){} void pushup(int tr,int l,int r) { if(col[tr]) { sum[tr]=__hash[r+1]-__hash[l];lb[tr]=rb[tr]=1;num[tr]=2;} else { if(l==r) { sum[tr]=0;lb[tr]=rb[tr]=0;num[tr]=0;} else{ sum[tr]=sum[tr<<1]+sum[tr<<1|1];lb[tr]=lb[tr<<1];rb[tr]=rb[tr<<1|1];num[tr]=num[tr<<1]+num[tr<<1|1];if(lb[tr<<1|1]&&rb[tr<<1])num[tr]-=2;}}} void update(int L,int R,int l,int r,int tr,int flag) { if(L<=l&&r<=R) { col[tr]+=flag; pushup(tr,l,r); return; } int mid=(l+r)>>1; if(L<=mid) update(L,R,l,mid,tr<<1,flag); if(R>mid) update(L,R,mid+1,r,tr<<1|1,flag); pushup(tr,l,r); } int main() { int n; while(scanf("%d",&n)!=EOF) { double x1,x2,y1,y2,lx=INF,rx=-INF; int i,k=1; for(i=1;i<=n;i++) { scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); a[k].x1=x1; a[k].x2=x2; a[k].y=y1; a[k].flag=1; __hash[k++]=x1; a[k].x1=x1; a[k].x2=x2; a[k].y=y2; a[k].flag=-1; __hash[k++]=x2; } sort(a+1,a+k,cmp); sort(__hash+1,__hash+k); memset(sum,0,sizeof(sum));memset(col,0,sizeof(col));memset(lb,0,sizeof(lb));memset(rb,0,sizeof(rb));memset(num,0,sizeof(num)); double ans=0,last=0; for(i=1;i<=k-1;i++) { int x,y; x=bseach(a[i].x1,k-1); y=bseach(a[i].x2,k-1)-1; if(x<=y) update(x,y,1,k-1,1,a[i].flag); ans+=num[1]*(a[i+1].y-a[i].y);ans+=fabs(sum[1]-last);last=sum[1]; } printf("%.lf\n",ans); } }
0 0
- HDOJ 题目1828 Picture (线段树+扫描线)
- 【线段树+扫描线】 HDOJ 1828 && POJ 1177 Picture
- HDU 1828 Picture(线段树:扫描线)
- hdu 1828 Picture 线段树+扫描线
- HDOJ 题目3265 Posters(线段树+扫描线)
- HDOJ 题目1264 Counting Squares(线段树+扫描线)
- 【HDU】1828-Picture(线段树扫描线)
- HDU 1828 Picture(线段树 + 扫描线)
- hdu 1828 Picture (线段树+扫描线)
- HDU 1828 Picture (线段树+扫描线+离散化)
- POJ题目 1151|| HDOJ 题目1542Atlantis(线段树+离散化+扫描线)
- hdu 1828 Picture(线段树&扫描线&周长并)
- hdu1828 Picture(扫描线+矩形周长并+线段树)
- poj - 1177 - Picture(离线化+扫描线+线段树)
- POJ 1177 Picture(线段树+扫描线)
- hdu1828 Picture (线段树+扫描线)(求周长并)
- HDU1828 Picture(线段树+扫描线求周长并)
- POJ 1177:Picture(线段树-扫描线)
- 转载一:OSM-Web服务器(一) PostgreSql 配置以及osm2pgsql原始PBF数据导入
- PostgreSQL 在3D 数据内容管理中的应用
- java锁机制
- C++实现分段双调排序算法
- 牛顿迭代法求平方根
- HDOJ 题目1828 Picture (线段树+扫描线)
- https
- Hadoop和YARN的关系
- 技巧:快速提高 Vi/Vim 使用效率的原则与途径
- 直方图均衡化原理
- 归并排序
- PostgreSQL earth distance module
- oracle10g 安装笔记
- 学习小结20151014--小标签