题目链接:http://poj.org/problem?id=1151

  扫描线+离散+线段树,线段树每个节点保存的是离散后节点右边的线段。

 //STATUS:C++_AC_16MS_208KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End struct Seg{
double y,x1,x2;
int c;
Seg(){}
Seg(double a,double b,double c,int d):y(a),x1(b),x2(c),c(d){}
bool operator < (const Seg& a)const{
return y<a.y;
}
}seg[N];
double hs[N],len[N<<];
int cnt[N<<];
int n,m; void pushup(int l,int r,int rt)
{
if(cnt[rt])len[rt]=hs[r+]-hs[l];
else if(l==r)len[rt]=;
else len[rt]=len[rt<<]+len[rt<<|];
} void update(int a,int b,int c,int l,int r,int rt)
{
if(a<=l && r<=b){
cnt[rt]+=c;
pushup(l,r,rt);
return;
}
int mid=(l+r)>>;
if(a<=mid)update(a,b,c,lson);
if(b>mid)update(a,b,c,rson);
pushup(l,r,rt);
} int binary(int l,int r,double tar)
{
int mid;
while(l<r){
mid=(l+r)>>;
if(hs[mid]==tar)return mid;
else if(hs[mid]>tar)r=mid;
else l=mid+;
}
return -;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,k,ca=,l,r;
double ans,a,b,c,d;
while(~scanf("%d",&n) && n)
{
m=;
for(i=;i<n;i++){
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
hs[m]=a;
seg[m++]=Seg(b,a,c,);
hs[m]=c;
seg[m++]=Seg(d,a,c,-);
}
sort(hs,hs+m);
sort(seg,seg+m);
for(i=,k=;i<m;i++)
if(hs[i]!=hs[k])hs[++k]=hs[i];
mem(len,);mem(cnt,);
ans=;
for(i=;i<m-;i++){
l=binary(,k+,seg[i].x1);
r=binary(,k+,seg[i].x2)-;
if(l<=r)update(l,r,seg[i].c,,k,);
ans+=len[]*(seg[i+].y-seg[i].y);
} printf("Test case #%d\nTotal explored area: %.2lf\n\n",ca++,ans);
}
return ;
}

POJ-1151 Atlantis 矩形面积并的更多相关文章

  1. POJ 1151 Atlantis 矩形面积求交/线段树扫描线

    Atlantis 题目连接 http://poj.org/problem?id=1151 Description here are several ancient Greek texts that c ...

  2. poj 1151(离散化+矩形面积并)

    题目链接:http://poj.org/problem?id=1151 关于离散化,这篇博客讲的很好:http://www.cppblog.com/MiYu/archive/2010/10/15/12 ...

  3. POJ 1151 Atlantis(扫描线)

    题目原链接:http://poj.org/problem?id=1151 题目中文翻译: POJ 1151 Atlantis Time Limit: 1000MS   Memory Limit: 10 ...

  4. POJ 1151 Atlantis(线段树-扫描线,矩形面积并)

    题目链接:http://poj.org/problem?id=1151 题目大意:坐标轴上给你n个矩形, 问这n个矩形覆盖的面积 题目思路:矩形面积并. 代码如下: #include<stdio ...

  5. hdu 1542&&poj 1151 Atlantis[线段树+扫描线求矩形面积的并]

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  6. POJ 1151 Atlantis 线段树求矩形面积并 方法详解

    第一次做线段树扫描法的题,网搜各种讲解,发现大多数都讲得太过简洁,不是太容易理解.所以自己打算写一个详细的.看完必会o(∩_∩)o 顾名思义,扫描法就是用一根想象中的线扫过所有矩形,在写代码的过程中, ...

  7. POJ 1151 Atlantis 求矩阵面积并 扫描线 具体解释

    题意: 给定n个矩阵的左下角和右上角坐标,求矩阵面积并(矩阵总是正放的,即与x轴y轴都平行) 思路: 扫描线裸题 http://www.cnblogs.com/fenshen371/p/3214092 ...

  8. POJ 1151 Atlantis 线段树+离散化+扫描线

    这次是求矩形面积并 /* Problem: 1151 User: 96655 Memory: 716K Time: 0MS Language: G++ Result: Accepted */ #inc ...

  9. 【HDU 1542】Atlantis 矩形面积并(线段树,扫描法)

    [题目] Atlantis Problem Description There are several ancient Greek texts that contain descriptions of ...

  10. (HDU 1542) Atlantis 矩形面积并——扫描线

    n个矩形,可以重叠,求面积并. n<=100: 暴力模拟扫描线.模拟赛大水题.(n^2) 甚至网上一种“分块”:分成n^2块,每一块看是否属于一个矩形. 甚至这个题就可以这么做. n<=1 ...

随机推荐

  1. 仿window阿里旺旺登陆界面,打印机吐纸动画效果-b

    偶然的机会发现window的阿里旺旺的登陆效果蛮有意思的,于是就模仿着做了一下打印机吐纸的动画效果看起来很神奇的东西,实现起来却不难,下面我给大家看下主要的源码. - (void)createUI{ ...

  2. 《深入理解计算机系统》C程序中常见的内存操作有关的典型编程错误

    对C/C++程序员来说,内存管理是个不小的挑战,绝对值得慎之又慎,否则让由上万行代码构成的模块跑起来后才出现内存崩溃,是很让人痛苦的.因为崩溃的位置在时间和空间上,通常是在距真正的错误源一段距离之后才 ...

  3. php调用whois接口域名查询

    由两部分组成,一个index.php文件,一个whois的接口文件: <html> <head> <title>域名到期查询</title> <s ...

  4. 让Eclipse使用新版本的JRE

    更新到新的 Mac OS X 再打开Eclipse 编译程序会报错, Exception in thread "main" java.lang.UnsupportedClassVe ...

  5. hdu 1423

    最长公共上升子序列:O(n*m)的算法: #include<cstdio> #include<cstring> #define maxn 1000 using namespac ...

  6. Codeforces Round #232 (Div. 1)

    这次运气比较好,做出两题.本来是冲着第3题可以cdq分治做的,却没想出来,明天再想好了. A. On Number of Decompositions into Multipliers 题意:n个数a ...

  7. asp.net将数据库中的数据赋给DropDownList

    当你选定一项进行其他操作时会重新绑定dropdownlist,这样会重新回到第一项,在page_load里加上判断if(!IsPostBack){'这里是你需要绑定dropdownlist的代码'}. ...

  8. 命令行静态编译QT程序

    在.pro文件里加上(非必须)CONFIG += static release windows 静态库必须放在这个路径:C:\Qt\Qt5.3.2_static\bin\qmake -makefile ...

  9. Tomcat 6.0下配置HTTPS

    最近项目需要使用到https,所以回顾整理了一下,其实在tomcat的文档中已经有了详细描述,我们启动Tomcat后,可以在docs文档中找到 地址如下:http://localhost:8080/d ...

  10. WebBrowser控件的高级定制+mshtml

    --> blog:WebBrowser控件的高级定制---以下为三篇重要的参考文献,    第一篇可以禁用了js弹窗和声音    第二篇的引用文献禁用了IE弹窗,但是原文的说明很好    第3篇 ...