HDU 1255 覆盖的面积
来源:互联网 发布:品牌营销找优爵网络 编辑:程序博客网 时间:2024/04/30 12:51
#include "cstdio"#include "algorithm"using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=2222;struct edge{ double a,b,h; int s;};edge e[maxn];bool cmp(edge &p,edge &q){return p.h<q.h;}double sum[maxn<<2],len[maxn<<2];int cnt[maxn<<2];double x[maxn];void pushup(int l,int r,int rt){ if(cnt[rt]>=2) sum[rt]=len[rt]=x[r+1]-x[l]; else if(cnt[rt]>0) len[rt]=x[r+1]-x[l],sum[rt]=len[rt<<1]+len[rt<<1|1]; else if(l>=r) sum[rt]=len[rt]=0; else sum[rt]=sum[rt<<1]+sum[rt<<1|1],len[rt]=len[rt<<1]+len[rt<<1|1];}void update(int L,int R,int c,int l,int r,int rt){ if(L<=l&&R>=r){ cnt[rt]+=c; pushup(l,r,rt); return; } int m=(l+r)>>1; if(L<=m) update(L,R,c,lson); if(R>m) update(L,R,c,rson); pushup(l,r,rt);}int bst(double v,double x[],int n){ int l=0,r=n-1,m; while(l<=r){ m=(l+r)>>1; if(x[m]==v) return m; if(x[m]<v) l=m+1; else r=m-1; } return -1;}int main(){ int n; int t; scanf("%d",&t); double a,b,c,d; while(t--){ scanf("%d",&n); int m=0; double ans=0; for(int i=0;i<n;i++){ scanf("%lf%lf%lf%lf",&a,&b,&c,&d); x[m]=a; e[m].a=a,e[m].b=c,e[m].h=b,e[m++].s=1; x[m]=c; e[m].a=a,e[m].b=c,e[m].h=d,e[m++].s=-1; } sort(x,x+m); sort(e,e+m,cmp); int k=1; int L,R; for(int i=1;i<m;i++){ if(x[i]!=x[i-1]) x[k++]=x[i]; } memset(cnt,0,sizeof(cnt)); memset(sum,0,sizeof(sum)); memset(len,0,sizeof(len)); //printf("%d\n",k); //for(int i=0;i<k;i++) printf("%.2lf ",x[i]); //printf("\n"); for(int i=0;i<m-1;i++){ L=bst(e[i].a,x,k); R=bst(e[i].b,x,k)-1; //printf("%d %d\n",L,R); if(R>=L) update(L,R,e[i].s,0,k-1,1); //for(int i=1;i<=16;i++) printf("%d ",cnt[i]); //printf("\n"); ans+=sum[1]*(e[i+1].h-e[i].h); //printf("%.2lf %.2lf\n",sum[1],ans); } printf("%.2lf\n",ans); } return 0;}
0 0
- hdu 1255 覆盖的面积
- hdu 1255 覆盖的面积
- hdu 1255 覆盖的面积
- HDU 1255 覆盖的面积
- HDU-1255-覆盖的面积
- hdu 1255 覆盖的面积
- Hdu 1255 覆盖的面积
- HDU 1255 覆盖的面积
- hdu 1255 覆盖的面积
- HDU 1255 覆盖的面积
- HDU 1255 覆盖的面积
- HDU 1255 覆盖的面积
- HDU 1255 覆盖的面积
- hdu 1255 覆盖的面积
- hdu 1255 覆盖的面积
- hdu 1255 覆盖的面积(矩形面积并,多次覆盖)
- 覆盖的面积 HDU
- 覆盖的面积 HDU
- winForm状态栏StatusStrip
- Light Pre-Pass 渲染器----为多光源设计一个渲染器
- sublime搜索和替换--多文件搜索替换
- CakePHP查询数据详解
- C 文件读写整理
- HDU 1255 覆盖的面积
- ImageMagicK 图片尺寸转换
- hdu 1272 小希的迷宫
- VisionEngine游戏对象中装饰组介绍
- (三)树莓派交叉编译环境配置
- 由于单表数据已经达到2000万数据,所以想分表,现假如分1000万为一单表,例有如一两个表:
- Deferred Lighting (延迟光照) + Light Pre-Pass 实现多光源动态阴影
- Cocos2dx+lua中调用按键监听
- DHCP协议和dhcpcd源码分析