题目链接: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. wpf 只在window是ShowDialog打开时才设置DialogResult

    //only set DialogResult when window is ShowDialog before if(System.Windows.Interop.ComponentDispatch ...

  2. CentOS 6.6x64下编译gcc-4.7.4

    最近使用老版本的gcc发现一些问题,于是想尝试升级. 看了一些教程之后进行尝试,发现各类教程均会有一些小问题,于是在此记录一下本人的过程. 编译过程中参考的文章有如下几篇,在此表示感谢: http:/ ...

  3. unity的旋转

    绕着一个点旋转 : transform.RotateAround(Vector3.zero, Vector3.up, speed* Time.deltaTime ); 第一个参数,点的位置.第二个参数 ...

  4. iphone下overflow失效问题的解决方法

    overflow-y: auto; -webkit-overflow-scrolling:touch; /*加上这个让浏览器支持touch和自动滚动这样界面就可以滚动了*/

  5. Nhibernate 一对多,多对一配置

    先来分析下问题,这里有两张表:Users(用户表) U和PersonalDynamic(用户动态表) PD,其中PD表的UserId对应U表的Id 如图: 现在映射这两张表: 如图: User.hbm ...

  6. hdu 1403 Longest Common Substring(最长公共子字符串)(后缀数组)

    http://acm.hdu.edu.cn/showproblem.php?pid=1403 Longest Common Substring Time Limit: 8000/4000 MS (Ja ...

  7. ASP.NET 使用mode=”InProc”方式保存Session老是丢失,无奈改成StateServer 模式。

    http://blog.csdn.net/fox123871/article/details/8165431 session是工作在你的应用程序进程中的.asp.net进程.iis往往会在20分钟之后 ...

  8. HDU 1171 Big Event in HDU(DP)

    点我看题目 题意 : 给你一个n,然后n组数据,每组两个数字,一个是物品的价值,另外一个是物品的数量,让你尽量将这些东西分成价值相等的两份,如果无法相等就前一份要大于后一份. 思路 :这个题可以转化成 ...

  9. J2EE的十三种技术(规范)

    J2EE的十三种技术(规范)  Java数据库连接(JDBC) JDBC API以一个统一的方式访问各种数据库.与ODBC类似,JDBC将开发者和私有数据库之间的问题隔离开来.由于它建立在Java上, ...

  10. SPRING IN ACTION 第4版笔记-第七章Advanced Spring MVC-001- DispatcherServlet的高级配置(ServletRegistration.Dynamic、WebApplicationInitializer)

    一. 1.如想在DispatcherServlet在Servlet容器中注册后自定义一些操作,如开启文件上传功能,则可重写通过AbstractAnnotationConfigDispatcherSer ...