覆盖的面积(HDU 1255 线段树)
覆盖的面积
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

注意:本题的输入数据较多,推荐使用scanf读入数据.
2
5
1 1 4 2
1 3 3 7
2 1.5 5 4.5
3.5 1.25 7.5 4
6 3 10 7
3
0 0 1 1
1 0 2 1
2 0 3 1
7.63
0.00 线段树计算被覆盖部分的面积#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#define LL long long using namespace std; const int Max = 1000; typedef struct Tree
{
int num;
double OneL,TwoL;//记录区间被覆盖多于一次和两次的长度
}Tree; Tree Tr[Max*10]; typedef struct Point
{
double x;
double y1;
double y2;
int op;
bool operator < (const struct Point a)const
{
return x<a.x;
} }Point; Point P[Max*3]; vector <double>y; int T,n; void Pushup(int L,int R,int st)
{
if(Tr[st].num>=2)
{
Tr[st].TwoL=Tr[st].OneL=y[R-1]-y[L-1];
return ;
}
if(Tr[st].num==1)
{
if(L+1==R)
{
Tr[st].TwoL=0;
Tr[st].OneL=y[R-1]-y[L-1];
}
else
{
Tr[st].OneL=y[R-1]-y[L-1];
Tr[st].TwoL=Tr[st<<1].OneL+Tr[st<<1|1].OneL;
}
return ;
}
if(Tr[st].num==0)
{
if(L+1==R)
{
Tr[st].OneL=Tr[st].TwoL=0;
}
else
{
Tr[st].OneL=Tr[st<<1].OneL+Tr[st<<1|1].OneL;
Tr[st].TwoL=Tr[st<<1].TwoL+Tr[st<<1|1].TwoL;
}
return ;
}
}
void Build(int L,int R,int st)
{
Tr[st].num=0;
Tr[st].OneL=Tr[st].TwoL=0;
if(L+1==R)
{
return ;
}
int mid = (L+R)>>1; Build(L,mid,st<<1); Build(mid,R,st<<1|1); Pushup(L,R,st);
} void Update(int L,int R,int st,int l,int r,int d)
{
if(l>=R||r<=L)
{
return ;
}
if(L>=l&&R<=r)
{
Tr[st].num+=d;
Pushup(L,R,st);
return ;
}
int mid = (L+R)>>1;
if(l<=mid)
{
Update(L,mid,st<<1,l,r,d);
}
if(r>mid)
{
Update(mid,R,st<<1|1,l,r,d);
}
Pushup(L,R,st); } int main()
{
double x1,x2,y1,y2; scanf("%d",&T); while(T--)
{
scanf("%d",&n); y.clear(); map<double ,int >M; int m=0; for(int i=0;i<n;i++)
{
scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2); P[m].x=x1; P[m].y1=y1; P[m].op=1; P[m++].y2=y2; P[m].x=x2; P[m].y1=y1; P[m].op=-1; P[m++].y2=y2; y.push_back(y1); y.push_back(y2);
} sort(P,P+m); sort(y.begin(),y.end()); y.erase(unique(y.begin(),y.end()),y.end());//去重 int sum = y.size(); for(int i=0;i<sum;i++)//重新编号
{
M[y[i]]=i+1;
} double Area =0 ; double h; Build(1,sum,1); for(int i=0;i<m-1;i++)
{
Update(1,sum,1,M[P[i].y1],M[P[i].y2],P[i].op);
h=P[i+1].x-P[i].x;
Area += (h*Tr[1].TwoL);//计算面积
}
printf("%.2f\n",Area);
}
return 0;
}
覆盖的面积(HDU 1255 线段树)的更多相关文章
- 覆盖的面积 HDU - 1255 线段树+扫描线+离散化 求特定交叉面积
#include<cstdio> #include<map> #include<algorithm> using namespace std; ; struct N ...
- 线段树扫描线(一、Atlantis HDU - 1542(覆盖面积) 二、覆盖的面积 HDU - 1255(重叠两次的面积))
扫描线求周长: hdu1828 Picture(线段树+扫描线+矩形周长) 参考链接:https://blog.csdn.net/konghhhhh/java/article/details/7823 ...
- hdu 1255(线段树 扫描线) 覆盖的面积
http://acm.hdu.edu.cn/showproblem.php?pid=1255 典型线段树辅助扫描线,顾名思义扫描线就是相当于yy出一条直线从左到右(也可以从上到下)扫描过去,此时先将所 ...
- 覆盖的面积 HDU - 1255 (线段树-扫描线)模板提
给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. Input输入数据的第一行是一个正整数T(1<=T<=100),代表测试数据的数量.每个测试数据的第一行是一个正整数N(1& ...
- O - 覆盖的面积 - hdu 1255(求面积)
分析:求一层的面积覆盖是非常简单的事情,不过多层面积覆盖应该怎么搞???也是比较简单的事情,只需要用两个变量记录就好了,一个记录覆盖一次的,一个记录覆盖两次的,就很容易解决了 ************ ...
- 覆盖的面积 HDU - 1255(扫描线求面积交)
题意: 就是扫描线求面积交 解析: 参考求面积并.... 就是把down的判断条件改了一下..由w > 0 改为 w > 1 同时要讨论一下 == 1 时 的情况, 所以就要用到一个临时 ...
- HDU 1255 覆盖的面积 (扫描线 线段树 离散化 矩形面积并)
题目链接 题意:中文题意. 分析:纯手敲,与上一道题目很相似,但是刚开始我以为只是把cnt>=0改成cnt>=2就行了,. 但是后来发现当当前加入的线段的范围之前 还有线段的时候就不行了, ...
- 覆盖的面积 HDU - 1255 (扫描线, 面积交)
求n个矩阵面积相交的部分,和求面积并一样,不过这里需要开两个数组保存覆盖一次和覆盖两次以上的次数的部分,还是模板,主要注意点就是pushup部分,如果我已经被两次覆盖,那我的两个数组在这个root点的 ...
- 面积并+扫描线 覆盖的面积 HDU - 1255
题目链接:https://cn.vjudge.net/problem/HDU-1255 题目大意:中文题目 具体思路:和上一篇的博客思路差不多,上一个题求的是面积,然后我们这个地方求的是啊覆盖两次及两 ...
随机推荐
- JCreator的配置
1.在Configure(配置)菜单上选择Options(选项),将弹出对话框. 2.在Option对话框中选择左侧JDK Profile,选择右侧JDK version 1.x.x.. ,点击Edi ...
- 一次有趣的XSS漏洞挖掘分析(3)最终篇
这真是最后一次了.真的再不逗这个程序员了.和预期一样,勤奋的程序员今天又更新程序了.因为前面写的payload都有一个致命的弱点,就是document.write()会完全破坏DOM结构.而且再“完事 ...
- asp.net mvc Post上传文件大小限制
最近发现在项目中使用jQuery.form插件上传比较大的文件时,上传不了,于是改了下web.config的上传文件最大限制. <configuration> <system.web ...
- Linux_shell脚本_遍历文件夹下所有文件
参考:lunar1983的专栏 实现:从给定目录树中grep出含制定字符串的行,并给出所在路径 代码如下所示: #!/bin/sh - if [ $# -ne 2 ] then echo " ...
- js 检查是否为手机端
let isMobile = function(){ let userAgentInfo = navigator.userAgent; let Agents = new Array("And ...
- Codeforces Round #361 (Div. 2) C D
C 给出一个m 此时有 四个数 分别为x k*x k*k*x k*k*k*x k大于1 x大于等于1 要求求出来一个最小的值n 使其满足 这四个数中的最大值小于n 这四个数可能的组数为m 可以看出这四 ...
- 《最终幻想XV》中角色AI的意识决策系统解析
http://gad.qq.com/article/detail/7155321
- 关于IOS的证书、App ID、设备、Provisioning Profile详述
首先,打开developer.apple.com ,在iOS Dev Center打开Certificates, Indentifiers & Profiles认识一下基本结构.列表就包含了开 ...
- 使用Visual Studio 2015开发Android 程序
环境配置: 操作系统:win 7 64位 IDE:Visual Studio 2015 SDK:installer_r24.3.3-windows 安装前提: 编辑hosts文件(在附件可下载)因为安 ...
- ExtJs 使用点滴 十三 在FormPanel 嵌入按钮
Ext.onReady(function () { //初始化标签中的Ext:Qtip属性. Ext.QuickTips.init(); Ext.form.Field.prototype.msgTar ...