博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1828 Picture(线段树:扫描线 面积并)
阅读量:4701 次
发布时间:2019-06-09

本文共 2197 字,大约阅读时间需要 7 分钟。

题解+扫描线讲解:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 0x3f3f3f3f#define mem(a,b) memset(a,b,sizeof(a))#define ll long long#define sd(x) scanf("%d",&(x))#define sl(x) scanf("%lld",&(x))#define slf(x) scanf("%lf",&(x))#define scs(s) scanf("%s",s)#define rep(i,a,b) for(int i=a;i<=b;i++)#define per(i,a,b) for(int i=a;i>=b;i--)#define lowbit(x) x&(-x)#define ls now<<1#define rs now<<1|1#define lson l,mid,ls#define rson mid+1,r,rs#define All L,Rusing namespace std;const int maxn=2222;struct node{ double l,r,h; int d; bool operator <(const node cmp) const{ return h
>1; lazy[now]=tree[now]=0; if(l==r) return ; built(lson); built(rson);}void pushdown(int now,int l,int r){ int mid=(l+r)>>1; if(lazy[now]!=-1) { lazy[ls]=lazy[rs]=lazy[now]; tree[ls]=lazy[ls]?Hash[mid+1]-Hash[l]:0; tree[rs]=lazy[rs]?Hash[r+1]-Hash[mid+1]:0; }}void pushup(int now,int l,int r){ if(lazy[ls]==-1||lazy[rs]==-1||(lazy[rs]!=lazy[ls])) lazy[now]=-1; else lazy[now]=lazy[ls]; tree[now]=tree[ls]+tree[rs];}void update(int l,int r,int now,int L,int R,int c){ int mid=(l+r)>>1; if(L<=l&&r<=R) { if(lazy[now]!=-1) { lazy[now]+=c; tree[now]=lazy[now]?Hash[r+1]-Hash[l]:0; return ; } } pushdown(now,l,r); if(L<=mid) update(lson,All,c); if(R>mid) update(rson,All,c); pushup(now,l,r);}int bin(double key,int n,double d[]){ int l=1,r=n; while(r>=l) { int m=(r+l)/2; if(d[m]==key) return m; else if(d[m]>key) r=m-1; else l=m+1; }}int main(){ int t,tot=0; while(sd(t)&&t) { int n=0,m=0; double x1,x2,y1,y2; rep(i,1,t) { slf(x1),slf(y1),slf(x2),slf(y2); Hash[++n]=x1; Hash[++n]=x2; e[++m]=(node){x1,x2,y1,1}; e[++m]=(node){x1,x2,y2,-1}; } sort(e+1,e+1+m); sort(Hash+1,Hash+1+n); n=unique(Hash+1,Hash+1+n)-Hash-1; built(1,n-1,1); double ans=0; rep(i,1,m-1) { int l=lower_bound(Hash+1,Hash+1+n,e[i].l)-Hash; int r=lower_bound(Hash+1,Hash+1+n,e[i].r)-Hash-1; if(l<=r) update(1,n-1,1,l,r,e[i].d); ans+=tree[1]*(e[i+1].h-e[i].h); } printf("Test case #%d\nTotal explored area: %.2lf\n\n",++tot,ans); } return 0;}

 

转载于:https://www.cnblogs.com/minun/p/11295885.html

你可能感兴趣的文章
京东SSO单点登陆实现分析
查看>>
u-boot启动第一阶段
查看>>
MySQL批量SQL插入性能优化
查看>>
定义列属性:null,default,PK,auto_increment
查看>>
用户画像展示
查看>>
C#中StreamReader读取中文出现乱码
查看>>
使用BufferedReader的时候出现的问题
查看>>
批处理文件中的路径问题
查看>>
hibernate出现No row with the given identifier exists问题
查看>>
为什么wait()和notify()属于Object类
查看>>
配置NRPE的通讯
查看>>
匹配两个空格之间的字符。。。
查看>>
CSS 文字溢出 变成省略号 ...
查看>>
Spring事务
查看>>
java编程基础(三)流程控制语句
查看>>
让数据库跑的更快的7个MySQL优化建议
查看>>
jquery 取id模糊查询
查看>>
解决在vue中,自用mask模态框出来后,下层的元素依旧可以滑动的问题
查看>>
修改node节点名称
查看>>
PAT(B) 1014 福尔摩斯的约会(Java)
查看>>