这次是求矩形面积并

/*
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. jquery全局加载函数的几种方式;

    1.使用javascript方式(function(){})(); 2.使用jQuery(function($) {}); 3.使用$(document).ready(function(){}); 其 ...

  2. linux 常用命令 集锦

    第一章  LINUX简介及安装    1一.LINUX介绍    1二.LINUX安装    2三.LINUX目录    2四.总结来说:    3第二章 常用命令及帐户管理    4一.linux命 ...

  3. 1003: [ZJOI2006]物流运输trans - BZOJ

    Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球.这些星球通过 ...

  4. 优化SQL Server数据库查询方法

    SQL Server数据库查询速度慢的原因有很多,常见的有以下几种: 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计算列 ...

  5. 使用rsyslog+loganalzey收集日志显示客户端ip

    http://www.ituring.com.cn/article/128536 rsyslog localhost 转发 http://bigsec.net/one/tool/rsyslog.htm ...

  6. Redis-PHP-Hash 表相关API

    Hashes 相关 ================================ hDel - 删除一个哈希 key hExists - 检查哈希 key是否存在 hGet - 获得某哈希 key ...

  7. 每次都觉得很神奇的JS

    匿名,函数对象... var staff = [ {name: 'abruzzi', age: 24}, {name: 'bajmine', age: 26}, {name: 'chris', age ...

  8. HDU4608+模拟

    简单的模拟题. 暴力枚举 /* 模拟 */ #include<algorithm> #include<iostream> #include<string.h> #i ...

  9. MyEclipse 启动tomcat时报错:Cannot change deployment state from ERROR to REDEPLOYING.ds

    myeclipse 启动tomcat时报错:Cannot change deployment state from ERROR to REDEPLOYING.ds - 刘琦的专栏 - 博客频道 - C ...

  10. RxJava学习(三)

    变换 所谓变换,就是将事件序列中的对象或整个序列进行加工处理,转换成不同的事件或事件序列. 1) API 首先看一个 map() 的例子: Observable.just("images/l ...