这次是求矩形面积并

/*
Problem: 1151 User: 96655
Memory: 716K Time: 0MS
Language: G++ Result: Accepted
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
using namespace std;
const int maxn=;
double y[maxn*];
struct Line
{
int co;
double x,y1,y2;
void fun(double a,double b,double c,int d)
{
x=a;
y1=b;
y2=c;
co=d;
}
bool operator<(const Line &e)const
{
return x<e.x;
}
}line[maxn*];
struct Node
{
double s,t,len;
int co;
void change(int o)
{
co+=o;
if(co==) len=;
else len=t-s;
}
};
struct Segtree
{
Node tree[maxn*];
void build(int l,int r,int o)
{
tree[o].s=y[l];tree[o].t=y[r];
tree[o].co=;tree[o].len=;
if(l+<r)
{
int m=(l+r)>>;
build(l,m,o*);
build(m,r,o*+);
}
}
void pushup(int o)
{
tree[o].len=tree[o*].len+tree[o*+].len;
}
void update(int l,int r,int o,Line e)
{
if(l+==r)
{
tree[o].change(e.co);
return;
}
int m=(l+r)>>;
if(e.y1<tree[o*].t)update(l,m,o*,e);
if(e.y2>tree[o*+].s)update(m,r,o*+,e);
pushup(o);
}
}seg;
int main()
{
int n,ncase=;
while(~scanf("%d",&n),n)
{
int cnt=;
for(int i=;i<n;i++)
{
double x1,x2,y1,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
line[cnt].fun(x1,y1,y2,);
y[cnt++]=y1;
line[cnt].fun(x2,y1,y2,-);
y[cnt++]=y2;
}
sort(line,line+cnt);
sort(y,y+cnt);
int d=;
for(int i=;i<cnt;i++)
if(y[i]!=y[i-])y[d++]=y[i];
double ans=;
seg.build(,d-,);
seg.update(,d-,,line[]);
for(int i=;i<cnt;i++)
{
ans+=(line[i].x-line[i-].x)*seg.tree[].len;
seg.update(,d-,,line[i]);
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",++ncase,ans);
}
return ;
}

POJ 1151 Atlantis 线段树+离散化+扫描线的更多相关文章

  1. POJ 1151 - Atlantis 线段树+扫描线..

    离散化: 将所有的x轴坐标存在一个数组里..排序.当进入一条线段时..通过二分的方式确定其左右点对应的离散值... 扫描线..可以看成一根平行于x轴的直线..至y=0开始往上扫..直到扫出最后一条平行 ...

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

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

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

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

  4. 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  5. hdu1542 矩形面积并(线段树+离散化+扫描线)

    题意: 给你n个矩形,输入每个矩形的左上角坐标和右下角坐标. 然后求矩形的总面积.(矩形可能相交). 题解: 前言: 先说说做这道题的感受: 刚看到这道题顿时就懵逼了,几何 烂的渣渣.后来从网上搜题解 ...

  6. POJ 1151Atlantis 矩形面积并[线段树 离散化 扫描线]

    Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21734   Accepted: 8179 Descrip ...

  7. POJ 1177/HDU 1828 picture 线段树+离散化+扫描线 轮廓周长计算

    求n个图矩形放下来,有的重合有些重合一部分有些没重合,求最后总的不规则图型的轮廓长度. 我的做法是对x进行一遍扫描线,再对y做一遍同样的扫描线,相加即可.因为最后的轮廓必定是由不重合的线段长度组成的, ...

  8. Picture POJ - 1177 线段树+离散化+扫描线 求交叉图像周长

    参考  https://www.cnblogs.com/null00/archive/2012/04/22/2464876.html #include <stdio.h> #include ...

  9. hdu 1542 Atlantis(线段树,扫描线)

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

随机推荐

  1. doc下批处理文件的感想

    这段时间忙着为我们的爬虫程序做一个守护进程,想来想去还是用脚本比较好,所以用了点时间仔细的研究了一下,这里有一点点经验想分享给大家,也不能说是经验了,只能说是我写这个的时候所用到的知识: 1.task ...

  2. c#加密汇总【粘】

    方法一: SHA1[不可逆]     //须添加对System.Web的引用     using System.Web.Security;           ...           /// &l ...

  3. 请求管道与IHttpModule接口

    IHttpModule向实现类提供模块初始化和处置事件.  IHttpModule包含兩個方法: public void Init(HttpApplication context);public vo ...

  4. 1042: [HAOI2008]硬币购物 - BZOJ

    Description 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买si的价值的东西.请问每次有多少种付款方法.Input 第一行 ...

  5. maven添加jar包依赖

    maven的东西使用了一段时间,但是每次使用都多少有点含糊,所以总结一下. 目前主要使用是在jar包的控制上 原理: 在本地,指定一个文件夹,便是maven的仓库,maven会从远程的中央仓库中下载你 ...

  6. DataGrid表格控件

    代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--& ...

  7. WebUI框架

    Telerik Kendo UI http://demos.telerik.com/kendo-ui/window/right-to-left-support

  8. hdu 4712

    看了大牛的解法  第一次知道可以产生随机数解题   在计算hamming距离时用了位运算  很简便 /************************************************* ...

  9. spoj 297

    就是对距离进行二分找最大值 .... #include <cstring> #include <cstdio> #include <algorithm> #incl ...

  10. SQL Server CONVERT() 函数

    http://www.w3school.com.cn/sql/func_convert.asp 定义和用法 CONVERT() 函数是把日期转换为新数据类型的通用函数. CONVERT() 函数可以用 ...