---恢复内容开始---

LINK

题意:同POJ1151

思路:

/** @Date    : 2017-07-19 13:24:45
* @FileName: POJ 1389 线段树+扫描线+面积并 同1151.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; struct yuu
{
int l, r;
int flag;
int ll, rr;
int len;
}tt[N]; struct line{
int y, x1, x2;
int flag;
line(){}
line(int _x1, int _x2, int _y, int f){
x1 = _x1;
x2 = _x2;
y = _y;
flag = f;
}
};
line li[N];
int cmp(line a, line b)
{
return a.y < b.y;
}
double a[N], b[N]; void pushup(int p)
{
if(tt[p].flag > 0)
{
tt[p].len = tt[p].rr - tt[p].ll;
return ;
}
if(tt[p].l == tt[p].r - 1)
tt[p].len = 0;
else
tt[p].len = tt[p << 1].len + tt[p << 1 | 1].len;
}
void build(int l, int r, int p)
{
tt[p].l = l;
tt[p].r = r;
tt[p].len = tt[p].flag = 0;
tt[p].ll = a[l];
tt[p].rr = a[r];
if(l == r - 1)
return ;
int mid = (l + r) >> 1;
build(l, mid, p << 1);
build(mid, r, p << 1 | 1);
} void update(int x1, int x2, int flag, int p)
{
if(x1 == tt[p].ll && x2 == tt[p].rr)
{
tt[p].flag += flag;
pushup(p);
return ;
}
if(x2 <= tt[p << 1].rr)
update(x1, x2, flag, p << 1);
else if(x1 >= tt[p << 1 | 1].ll)
update(x1, x2, flag, p << 1 | 1);
else
{
update(x1, tt[p << 1].rr, flag, p << 1);
update(tt[p << 1 | 1].ll, x2, flag, p << 1 | 1);
}
pushup(p);
} int main()
{
int x1, x2, y1, y2;
while(~scanf("%d%d%d%d", &x1, &y1, &x2, &y2) && ( (~x1) || (~x2) || (~y1) || (~y2)))
{
int cnt = 1;
li[cnt] = line(x1, x2, y1, 1);
a[cnt++] = x1;
li[cnt] = line(x1, x2, y2, -1);
a[cnt++] = x2;
while(scanf("%d%d%d%d", &x1, &y1, &x2, &y2) && (((~x1)||(~x2)||(~y1)||(~y2))))
{
li[cnt] = line(x1, x2, y1, 1);
a[cnt++] = x1;
li[cnt] = line(x1, x2, y2, -1);
a[cnt++] = x2;
}
sort(li + 1, li + cnt, cmp);
sort(a + 1, a + cnt);
build(1, cnt - 1, 1);
update(li[1].x1, li[1].x2, li[1].flag, 1);
int ans = 0;
for(int i = 2; i < cnt; i++)
{
//cout << li[i].x1 << "#" << li[i].x2 << "#" << li[i].y << endl;
ans += tt[1].len * (li[i].y - li[i - 1].y);
update(li[i].x1, li[i].x2, li[i].flag, 1);
//cout << "~";
}
printf("%d\n", ans); }
return 0;
}

---恢复内容结束---

POJ 1389 Area of Simple Polygons 扫描线+线段树面积并的更多相关文章

  1. POJ1389:Area of Simple Polygons——扫描线线段树题解+全套代码注释

    http://poj.org/problem?id=1389 题面描述在二维xy平面中有N,1 <= N <= 1,000个矩形.矩形的四边是水平或垂直线段.矩形由左下角和右上角的点定义. ...

  2. POJ 1389 Area of Simple Polygons | 扫描线

    请戳此处 #include<cstdio> #include<algorithm> #include<cstring> #define N 1010 #define ...

  3. 【POJ 1389】Area of Simple Polygons(线段树+扫描线,矩形并面积)

    离散化后,[1,10]=[1,3]+[6,10]就丢了[4,5]这一段了. 因为更新[3,6]时,它只更新到[3,3],[6,6]. 要么在相差大于1的两点间加入一个值,要么就让左右端点为l,r的线段 ...

  4. [poj] 1389 Area of Simple Polygons

    原题 线段树+扫描线 对于这样一个不规则图形,我们要求他的面积有两种方法,割和补. 补显然不行,因为补完你需要求补上去的内部分不规则图形面积-- 那么怎么割呢? 像这样: 我们就转化成了无数个矩形的和 ...

  5. POJ Area of Simple Polygons 扫描线

    这个题lba等神犇说可以不用离散化,但是我就是要用. 题干: Description There are N, <= N <= , rectangles -D xy-plane. The ...

  6. HDU 3265/POJ 3832 Posters(扫描线+线段树)(2009 Asia Ningbo Regional)

    Description Ted has a new house with a huge window. In this big summer, Ted decides to decorate the ...

  7. HDU 3642 - Get The Treasury - [加强版扫描线+线段树]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

  8. hdu1542 Atlantis(扫描线+线段树+离散)矩形相交面积

    题目链接:点击打开链接 题目描写叙述:给定一些矩形,求这些矩形的总面积.假设有重叠.仅仅算一次 解题思路:扫描线+线段树+离散(代码从上往下扫描) 代码: #include<cstdio> ...

  9. POJ 2828 Buy Tickets(排队问题,线段树应用)

    POJ 2828 Buy Tickets(排队问题,线段树应用) ACM 题目地址:POJ 2828 Buy Tickets 题意:  排队买票时候插队.  给出一些数对,分别代表某个人的想要插入的位 ...

随机推荐

  1. 技嘉主板+AMD CPU开启CPU虚拟化方法

    硬件环境:技嘉AB350+AMD Ryzen 5 1600X 由于安装虚拟机的需要,所以要开启CPU的虚拟化. 首先进入BIOS. 然后如图:(M.I.T-高级频率设定-CPU超频进阶设置-SVM M ...

  2. mac下mysql5.7.10密码问题

    mysql5.7.10刚安装好,会生成一个随机密码. 如果没记住这个随机密码,那么到mysql/bin/下执行mysql_secure_installation命令 按照提示重置密码和其他选项. ps ...

  3. flink写入mysql的两种方式

    方式一 通过JDBCOutputFormat 在flink中没有现成的用来写入MySQL的sink,但是flink提供了一个类,JDBCOutputFormat,通过这个类,如果你提供了jdbc的dr ...

  4. iOS 关于MVC和MVVM设计模式的那些事

    一.概述 在 iOS 开发中,MVC(Model View Controller)是构建iOS App的标准模式,是苹果推荐的一个用来组织代码的权威范式.Apple甚至是这么说的.在MVC下,所有的对 ...

  5. 【设计模式】C++中的单例模式

    讲解来自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&id=4281275&uid=26611383 由于使用了POSIX函 ...

  6. 第194天:js---函数对象详解(arguments、length)

    一.函数即对象 function add1(a,b){ return a+b; } //Function对象的实例 -- 高级技巧 --- 写框架必须用的... //前面表示参数,后面表示函数语句 v ...

  7. 【.Net】C# 根据绝对路径获取 带后缀文件名、后缀名、文件名、不带文件名的文件路径

    1.c#根据绝对路径获取 带后缀文件名.后缀名.文件名.   1 string str =" F:\test\Default.aspx"; 2 string filename = ...

  8. Solr实现SQL的查询与统计--转载

    原文地址:http://shiyanjun.cn/archives/78.html Cloudera公司已经推出了基于Hadoop平台的查询统计分析工具Impala,只要熟悉SQL,就可以熟练地使用I ...

  9. 【uoj#175】新年的网警 结论题+Hash

    题目描述 给出一张 $n$ 个点 $m$ 条边的无向连通图,每条边的边权为1.对于每个点 $i$ ,问是否存在另一个点 $j$ ,使得对于任意一个不为 $i$ 或 $j$ 的点 $k$ ,$i$ 到 ...

  10. BZOJ4878 挑战NP-Hard(dfs树)

    既然是二选一,考虑两个问题有什么联系.题面没有说无解怎么办,所以如果不存在经过k条边的简单路径,一定存在k染色方案.考虑怎么证明这个东西,我们造一棵dfs树.于是可以发现如果树深>k(根节点深度 ...