【线段树】Atlantis
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 23181 | Accepted: 8644 |
Description
Input
The input file is terminated by a line containing a single 0. Don't process it.
Output
Output a blank line after each test case.
Sample Input
2
10 10 20 20
15 15 25 25.5
0
Sample Output
Test case #1
Total explored area: 180.00
Source
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; inline int read(){
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int MAXN=100001;
const int INF=999999;
int N,M;
double a[100001],b[100001];
int A[100001];
struct data2{
double sum,len;
int ct;
}tr[1000001];
int tmp,tmp2;
struct data{
double x,y1,y2;
bool end;
}poi[1000001];
int T; bool cmp(data a,data b){
return a.x<b.x;
}
void build(int l,int r,int rt){
tr[rt].ct=0;tr[rt].sum=0;
tr[rt].len=a[r]-a[l];
if(l+1>=r) return ;
int mid=(l+r)>>1;
build(l,mid,rt*2);
build(mid,r,rt*2+1);
return ;
}
void Update(int rt,int l,int r){
if(tr[rt].ct) tr[rt].sum=tr[rt].len;
else if(r-l>1) tr[rt].sum=tr[rt*2].sum+tr[rt*2+1].sum;
else tr[rt].sum=0;
return ;
}
void add(int l,int r,int rt,int L,int R){
if(L==l&&R==r){
tr[rt].ct++;
Update(rt,l,r);
return ;
}
int mid=(l+r)>>1;
if(L>=mid) add(mid,r,rt*2+1,L,R);
else if(R<=mid) add(l,mid,rt*2,L,R);
else{
add(mid,r,rt*2+1,mid,R);
add(l,mid,rt*2,L,mid);
}
Update(rt,l,r);
return;
}
void del(int l,int r,int rt,int L,int R){
if(L==l&&R==r){
tr[rt].ct--;
Update(rt,l,r);
return ;
}
int mid=(l+r)>>1;
if(L>=mid) del(mid,r,rt*2+1,L,R);
else if(R<=mid) del(l,mid,rt*2,L,R);
else{
del(mid,r,rt*2+1,mid,R);
del(l,mid,rt*2,L,mid);
}
Update(rt,l,r);
return;
} double ans;
int main(){
while(1){
N=read();
if(!N) break;
tmp2=tmp=0;double x1,x2,y1,y2;
for(int i=1;i<=N;i++){
cin>>x1>>y1>>x2>>y2;
poi[++tmp].x=x1;
poi[tmp].y1=y1;
poi[tmp].y2=y2;
poi[tmp].end=false;
poi[++tmp].x=x2;
poi[tmp].y1=y1;
poi[tmp].y2=y2;
poi[tmp].end=true;
}
for(int i=1;i<=tmp;i+=2){
a[tmp2]=b[tmp2]=poi[i].y1;tmp2++;
a[tmp2]=b[tmp2]=poi[i].y2;tmp2++;
}
sort(poi+1,poi+tmp+1,cmp);
sort(a,a+tmp2);
int tmp3=0,tmp4=0;
tmp3=unique(a,a+tmp2)-a;
ans=0;
build(0,tmp3-1,1);
double lasth;
for(int i=1;i<tmp;i++){
if(!poi[i].end) add(0,tmp3-1,1,lower_bound(a,a+tmp3,poi[i].y1)-a,lower_bound(a,a+tmp3,poi[i].y2)-a);
else del(0,tmp3-1,1,lower_bound(a,a+tmp3,poi[i].y1)-a,lower_bound(a,a+tmp3,poi[i].y2)-a);
ans+=(double)((poi[i+1].x-poi[i].x)*tr[1].sum);
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",++T,ans);
}
}
【线段树】Atlantis的更多相关文章
- 线段树---Atlantis
题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110064#problem/A Description There are se ...
- hdu 1542 Atlantis(线段树,扫描线)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 1542 Atlantis(线段树扫描线+离散化求面积的并)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- POJ 1542 Atlantis(线段树 面积 并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 参考网址:http://blog.csdn.net/sunmenggmail/article/d ...
- 【HDU 1542】Atlantis 矩形面积并(线段树,扫描法)
[题目] Atlantis Problem Description There are several ancient Greek texts that contain descriptions of ...
- 【POJ1151】Atlantis(线段树,扫描线)
[POJ1151]Atlantis(线段树,扫描线) 题面 Vjudge 题解 学一学扫描线 其实很简单啦 这道题目要求的就是若干矩形的面积和 把扫描线平行于某个轴扫过去(我选的平行\(y\)轴扫) ...
- hdu1542 Atlantis 线段树--扫描线求面积并
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some ...
- HDU 1542 Atlantis(线段树面积并)
描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...
- hdu1542 Atlantis (线段树+扫描线+离散化)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 1542 - Atlantis - [线段树+扫描线]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
随机推荐
- 代理设计模式iOS开发Demo(示例程序)源代码
iOS程序源代码下载链接:03-代理设计模式.zip28.3 KB // main.m // // main.m // 03-代理设计模式 // // Created by apple ...
- Java开源爬虫框架crawler4j
花了两个小时把Java开源爬虫框架crawler4j文档翻译了一下,因为这几天一直在学习Java爬虫方面的知识,今天上课时突然感觉全英文可能会阻碍很多人学习的动力,刚好自己又正在接触这个爬虫框架,所以 ...
- ctsc&apio2018八日游
day0: 早就知道自己是打酱油的..早就做好了打铁的准备.. Q:那你来干嘛 A:当然是来玩啊!!玩啊!啊!! emmmmm 抱着半期考不及格的卷子瑟瑟发抖地上了飞机. day1:报道!当然还有在宾 ...
- js 验证ip列表
如题. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...
- 2014ACM/ICPC亚洲区北京站题解
本题解不包括个人觉得太水的题(J题本人偷懒没做). 个人觉得这场其实HDU-5116要比HDU-5118难,不过赛场情况似乎不是这样.怀疑是因为老司机带错了路. 这套题,个人感觉动态规划和数论是两个主 ...
- 用vue实现登录页面
vue和mui一起完成登录页面(在hbuilder编辑器) <!DOCTYPE html> <html> <head> <meta charset=" ...
- [hadoop][基本原理]zookeeper场景使用
代码:https://github.com/xufeng79x/ZkClientTest 1. 简介 zookeeper的特性决定他适用到某些场景非常合适,比如典型的应用场景: 1.集群管理(Grou ...
- spring mvc注解文件上传下载
需要两个包: 包如何导入就不介绍了,前端代码如下(一定要加enctype="multipart/form-data"让服务器知道是文件上传): <form action=&q ...
- python_基于反射模拟Web框架路由系统
根据用户输入的内容,导入模块 #根据用户输入的内容,导入模块 inp = input("请输入模块名: ") print(inp,type(inp)) dd = __import_ ...
- MapReduce案例一:天气温度
1.需求 2.思路 3.代码实现 3.1MyWeather 类代码: 这个类主要是用来定义hadoop的配置,在执行计算程序时所需加载的一些类. package com.hadoop.mr.weath ...