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类型 ...
随机推荐
- 四、MongoDB的查询
一.MongoDB的下载.安装与部署 二.MongoDB的基础知识简介 三.MongoDB的创建.更新和删除 db.blogs.insert([ { "author": " ...
- DNS笔记 DNS区域集成到 Active Directory
可以将 DNS 区域集成到 Active Directory 中以提供增强的容错功能和安全性.OpenDNS Google Public DNS往返时间 (RTT) 远程访问服务 (RAS)域名与 ...
- php5 date()获得的时间不是当前时间
php自5.10起加入了时区的设置,在php中显示的时间都是格林威治标准时间,因此便与中国的用户会差八个小时. 修改php.ini中的 date.timezone 参数: [Date] ; Defin ...
- ajaxFileUpload增加附加参数
直接说方法: $.ajaxFileUpload({ data:{"a":123,"b":456};//附加参数,json格式 }); 然后在ajaxFileUp ...
- 怎么做QQ、微信等消息气泡
主XML: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android ...
- 使用WMIC永久设置你的环境变量
关于wmic,引用一下这位哥们儿的话http://technet.microsoft.com/en-us/library/bb742610.aspx: WMIC扩展WMI(Windows Manage ...
- WIN10系统 Solidworks 2015 Toolbox插件提示 failed to create toolboxl ibrary object 解决方法
网上大部分都是说卸载一个更新程序,但是在WIN10中根本没有. 但是也可通过以下方法解决: 1.关闭SW程序及进程,用管理员命令打开CMD 2.打开并复制SW目录,默认为 C:\Program Fil ...
- 小米miui5系统的webview在处理动画事件transitionEnd事件时,竟然要用transitionend才行
一般的安卓系统用的是webkitTransitionEnd, 而小米的系统我用了webkitTransitionEnd事件无法执行,只能用transitionend才会被执行,怪
- Redbean:入门(四) - 反射机制 以及 事务
<?php //引入rb入口文件 include_once 'rb.php'; //定义dsn以及相关的数据 $dsn = 'mysql:host=localhost;dbname=hwibs_ ...
- android----Java DES加密算法工具类
DESUtil类 public class DESUtil { private static byte[] iv = {0x12, 0x34, 0x56, 0x78, (byte) 0x90, (by ...