hdu 1255 覆盖的面积 矩阵面积交
来源:互联网 发布:ubuntu pyqt 安装 编辑:程序博客网 时间:2024/05/17 04:11
题意:
求n个矩阵面积交
分析:
其实和求矩阵面积并是一样的思想
我们只需增加一个nsum数组储存区间中覆盖2次及以上的长度就行
#include <bits/stdc++.h>#define maxn 200002#define tmp (st<<1)#define mid ((l+r)>>1)#define lson l,mid,tmp#define rson mid+1,r,tmp|1using namespace std;int cnt[maxn<<2];double sum[maxn<<2];double nsum[maxn<<2];double x[maxn];struct Seg{ double h,l,r; int s; Seg(){} Seg(double a,double b,double c,int d):l(a),r(b),h(c),s(d){} bool operator<(const Seg &cmp)const{ return h<cmp.h; }}ss[maxn];void push_up(int st,int l,int r){ if(cnt[st]==1){ sum[st]=x[r+1]-x[l]; nsum[st]=sum[tmp]+sum[tmp|1]; } else if(cnt[st]>=2)sum[st]=nsum[st]=x[r+1]-x[l]; else if(l==r)nsum[st]=sum[st]=0; else { sum[st]=sum[tmp]+sum[tmp|1]; nsum[st]=nsum[tmp]+nsum[tmp|1]; }}void update(int L,int R,int c,int l,int r,int st){ 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,m,loop; scanf("%d",&loop); while(loop--){ scanf("%d",&n); double a,b,c,d,ans=0; m=0; while(n--){ scanf("%lf%lf%lf%lf",&a,&b,&c,&d); x[m]=a; ss[m++]=Seg(a,c,b,1); x[m]=c; ss[m++]=Seg(a,c,d,-1); } sort(x,x+m); sort(ss,ss+m); for(int i=0;i<m;++i){ int l=lower_bound(x,x+m,ss[i].l)-x; int r=lower_bound(x,x+m,ss[i].r)-x-1; update(l,r,ss[i].s,0,m-1,1); ans+=nsum[1]*(ss[i+1].h-ss[i].h); } 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-1255-覆盖的面积
- hdu 1255 覆盖的面积
- mysql中没有提交的事务查询
- Linux 显示文件的某几行
- kubernetes(3):Centos7 安装 kubernetes admin 版本
- 数据结构与算法分析之AVL平衡树
- Android启动模式及Intent属性----重新认识Android(5)
- hdu 1255 覆盖的面积 矩阵面积交
- HDU 4612 Warm up
- JavaScript简单取得函数作用域内变量的方法
- 机器学习之Kmeans
- LoadRunner-receive time
- HTML给标签的点击事件绑定匿名函数
- 三、zedboard Linux内核编译
- Linux上网络编程
- css3实现的简单开关按钮代码实例: