poj 1389 扫描线
来源:互联网 发布:淘宝买的东西下架了 编辑:程序博客网 时间:2024/06/04 22:16
裸矩形并
ACcode:
#include <iostream>#include <cstdio>#include <algorithm>#define maxn 50005#define tmp (st<<1)#define mid ((l+r)>>1)#define lson l,mid,tmp#define rson mid+1,r,tmp|1#define ll long longusing namespace std;int sum[maxn<<2];int cnt[maxn<<2];struct Seg{ int l,r,h,s; Seg(){} Seg(int a,int b,int c,int d):l(a),r(b),h(c),s(d){} bool operator <(const Seg &cmp)const{ return h<cmp.h; }}ss[maxn<<4];void push_up(int st,int l,int r){ if(cnt[st])sum[st]=r-l+1; else if(l==r)sum[st]=0; else sum[st]=sum[tmp]+sum[tmp|1];}void update(int L,int R,int c,int l,int r,int st){ if(l>R||r<L)return; if(L<=l&&r<=R){ cnt[st]+=c; push_up(st,l,r); return ; } if(L<=mid)update(L,R,c,lson); if(R>mid)update(L,R,c,rson); push_up(st,l,r);}int main(){ int n,a,b,c,d,m; while(scanf("%d%d%d%d",&a,&b,&c,&d)&&a!=-1&&b!=-1&&c!=-1&&d!=-1){ m=0; ss[m++]=Seg(a,c,b,1); ss[m++]=Seg(a,c,d,-1); while(scanf("%d%d%d%d",&a,&b,&c,&d)&&a!=-1&&b!=-1&&c!=-1&&d!=-1){ ss[m++]=Seg(a,c,b,1); ss[m++]=Seg(a,c,d,-1); } sort(ss,ss+m); int ans=0; for(int i=0;i<m;++i){ update(ss[i].l,ss[i].r-1,ss[i].s,0,50000-1,1); ans+=sum[1]*(ss[i+1].h-ss[i].h); } printf("%d\n",ans); } return 0;}
0 0
- POJ 1389 (扫描线)
- POJ 1389 (扫描线)
- poj 1389 扫描线
- POJ 1151 扫描线
- POJ 2932 (扫描线)
- poj 1151 扫描线
- POJ 2932 扫描线思想
- poj 2932 Coneology 扫描线
- poj 1151 Atlantis 扫描线
- poj 3109 扫描线+bit
- POJ 1389 Area of Simple Polygons(扫描线)
- POJ 1389 Area of Simple Polygons 线段树 扫描线
- poj 1151 poj 1389 线段树+扫描线+离散化 [矩形的面积并]
- poj 1151 Atlantis(线段树 扫描线)
- POJ 1151 Atlantis(扫描线)
- 【扫描线法】&& poj 1177 && hdu 1828
- poj 1765 November Rain(扫描线)
- POJ 1151 - Atlantis 线段树+扫描线..
- 433-最长的单词
- MySQL数据库结构优化(一)
- pod search找不到自己trunk push的库的解决方法
- 二、makefile VPTAH vpath $@ $<
- jmeter后置处理器BeanShell PostProcessor连接redis获取value
- poj 1389 扫描线
- Spring @Autowired注解
- AF请求数据失败,提示Request failed: unacceptable content-type: text/html
- Wake lock in LocationManagerService
- spring事务切面对织入自定义锁服务的启示
- Oracle中将数字金额转化为大写
- Python 运行cv2中出现的问题
- Linux内核sk_buff结构分析
- retrofit