Poj 1255 覆盖的面积 2014-07-28 12:29 116人阅读 评论(0) 收藏
覆盖的面积
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3553 Accepted Submission(s): 1743

注意:本题的输入数据较多,推荐使用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<algorithm>
#define Max 10005
using namespace std;
struct line{
double x, y1, y2;
int flag;
}x_line[Max]; struct node{
int l, r, flag;
double x, f;
}tree[Max]; double point[Max];
int n, m, xm; int cmp(double a,double b)
{
return a<b;
} bool comp(line a,line b)
{
return a.x<b.x;
} void Build(int l,int r,int k)
{
int m;
tree[k].l = l;
tree[k].r = r;
tree[k].flag = 0;
tree[k].x = 0.0;
tree[k].f = 0.0;
if(l+1 == r) return;
m = (l+r)>>1;
Build(l,m,k+k);
Build(m,r,k+k+1);
} void Myscanf()
{
m = 1;
double x1,x2,y1,y2;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
point[m] = y1;
x_line[m].x = x1;
x_line[m].y1 = y1;
x_line[m].flag = 1;
x_line[m++].y2 = y2;
point[m] = y2;
x_line[m].x = x2;
x_line[m].y1 = y1;
x_line[m].flag = -1;
x_line[m++].y2 = y2;
} } void Point_Do()
{
int mi = 0;
sort(point+1,point+m,cmp);
sort(x_line+1,x_line+m,comp);
xm = m;
for(int i=1; i<m; i++)
{
if(point[i]!=point[mi]) point[++mi] = point[i]; //去重
}
m = mi;
} int Bin(double xi)
{
int l = 1, r = m;
int mi;
while(l<=r)
{
mi = (l+r)>>1;
if(xi == point[mi]) return mi;
if(xi > point[mi]) l = mi+1;
else r = mi-1;
}
return -1;
} void update(int l, int r, int k, line cur)
{
if(tree[k].l==tree[k].r-1)
{
if(tree[k].flag == 1 && cur.flag == 1) tree[k].f = cur.x;
else if(tree[k].flag==2 && cur.flag==-1){
tree[k].x +=( cur.x - tree[k].f );
tree[k].f = 0.0;
}
tree[k].flag+=cur.flag;
return;
}
int mi = (tree[k].l+tree[k].r)>>1;
if(l>=mi) update(l,r,k+k+1,cur);
else if(r<=mi) update(l,r,k+k,cur);
else{
update(l,mi,k+k,cur);
update(mi,r,k+k+1,cur);
}
return;
} double query(int k)
{
if(tree[k].l + 1==tree[k].r) return (point[tree[k].r]-point[tree[k].l])*tree[k].x;
return query(k+k) + query(k+k+1);
} int Ans()
{
for(int i=1;i<xm;i++)
{
int x = Bin(x_line[i].y1);
int y = Bin(x_line[i].y2);
update(x,y,1,x_line[i]);
}
} int main()
{
int Case;
scanf("%d",&Case);
while(Case--)
{
memset(tree,0,sizeof(tree));
memset(point,-1,sizeof(point));
memset(x_line,0,sizeof(x_line));
Myscanf();
Point_Do();
Build(1,m,1);
Ans();
printf("%.2lf\n",query(1));
} return 0;
}
主要思路就是将y轴离散为线段树,然后,将x轴转换为状态,其实也可以x为线段树,y为状态的
版权声明:本文为博主原创文章,未经博主允许不得转载。
Poj 1255 覆盖的面积 2014-07-28 12:29 116人阅读 评论(0) 收藏的更多相关文章
- A Knight's Journey 分类: POJ 搜索 2015-08-08 07:32 2人阅读 评论(0) 收藏
A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35564 Accepted: 12119 ...
- 欧拉回路-Door Man 分类: 图论 POJ 2015-08-06 10:07 4人阅读 评论(0) 收藏
Door Man Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2476 Accepted: 1001 Description ...
- Black Box 分类: POJ 栈和队列 2015-08-05 14:07 2人阅读 评论(0) 收藏
Black Box Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8754 Accepted: 3599 Description ...
- Borg Maze 分类: POJ 2015-07-27 15:28 5人阅读 评论(0) 收藏
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9971 Accepted: 3347 Description The B ...
- Dirichlet's Theorem on Arithmetic Progressions 分类: POJ 2015-06-12 21:07 7人阅读 评论(0) 收藏
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- Self Numbers 分类: POJ 2015-06-12 20:07 14人阅读 评论(0) 收藏
Self Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22101 Accepted: 12429 De ...
- Counterfeit Dollar 分类: POJ 2015-06-12 15:28 19人阅读 评论(0) 收藏
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 41559 Accepted: 13 ...
- Poj 2559 最大矩形面积 v单调栈 分类: Brush Mode 2014-11-13 20:48 81人阅读 评论(0) 收藏
#include<iostream> #include<stack> #include<stdio.h> using namespace std; struct n ...
- java面试和笔试大全 分类: 面试 2015-07-10 22:07 10人阅读 评论(0) 收藏
2.String是最基本的数据类型吗? 基本数据类型包括byte.int.char.long.float.double.boolean和short. java.lang.String类是final类型 ...
随机推荐
- jQuery 遍历each()的使用方法
.each()是一个for循环的包装迭代器.each()通过回调的方式处理,并且会有2个固定的实参,索引与元素(从0开始计数).each()回调方法中的this指向当前迭代的dom元素 遍历方法: & ...
- CSS中的content和attr的用法
问题缘起 在闲看别人网站时发现了这样的代码 <span class="hamburger icon" data-icon="C"> .icon:be ...
- centos+php+coreseek+sphinx+mysql之二sphinx配置篇
先进入文件夹进行以下操作 cd /usr/local/coreseek/etc cp sphinx.conf.dist sphinx.conf source src1 { sql_host = 127 ...
- php读取excel文件 更新修改excel
php读取excel文件示例,还有更新修改功能. 代码: //模板存放目录 $dir = $DOCUMENT_ROOT.'/backoffice/admin/oemcheck/'; $template ...
- WebBrowser里网页根据文字判断来点击链接 无Name及ID时
uses ActiveX, ComObj, MSHTML; 根据连接文字点击连接- 一般情况下的连接 Procedure HTMLClinkByText(text:string;Wbr:TWebBro ...
- 每日一练--C语言--串
目标 实现串的经典模式匹配算法与KMP算法. 简述 自定义串结构: 串采用定长顺序存储结构,串从下标1开始存储,0下标存储串的实际长度: 匹配成功返回匹配位置,匹配失败返回0. #include &l ...
- EMVTag系列8《IC卡公钥证书》
Ø 9F46 IC卡公钥证书 L: NI -C(有条件):如果支持DDA 发卡行认证过的IC 卡公钥 Ø 9F47 IC卡公钥指数 F: b T: 9F47 L: 1 or 3 C:如 ...
- 2天驾驭DIV+CSS (技巧篇)(转)
这是去年看到的一片文章,感觉在我的学习中,有不少的影响.于是把它分享给想很快了解css的兄弟们.本文是技巧篇. 基础篇[知识一] “DIV+CSS” 的叫法是不准确的[知识二] “DIV+CSS” ...
- BASE64与单向加密算法MD5&SHA&MAC
言归正传,这里我们主要描述Java已经实现的一些加密解密算法,最后介绍数字证书. 如基本的单向加密算法: BASE64 严格地说,属于编码格式,而非加密算法 MD5(Message Diges ...
- 记录:asp.net mvc 中 使用 jquery 实现html5 实现placeholder 密码框 提示兼容password IE6
@{ViewBag.Title = "完美结合";} <script>var G_start_time = new Date;</script> <! ...