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

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. 常用IDE插件

    Visual Studio 常用 Refactoring Essentials:代码重构分析 Roslynator:代码重构 CodeMaid:代码格式化 Github Extension for V ...

  2. linux桌面使用鼠标中间健粘帖

    使用linux桌面很久了,一直习惯鼠标左键选中,右健弹出菜单复制粘帖. 没想到linux使用鼠标中间健粘帖,很方便. 参考:Linux鼠标中键复制粘贴之谜[Felix蛋疼科普贴] 用鼠标左键单击待复制 ...

  3. 转 docker的下载与安装

    百度网盘下载地址:https://oomake.com/download/docker-windows 道客地址: https://link.jianshu.com/?t=https://get.da ...

  4. Git(未完待续)

    Git的历史咱们就不多说来,我还是喜欢直白点,直接来干货吧 在Linux上安装Git 不同的系统不同的安装命令,基础的就不说来,centos直接yum就ok. 安装完成后,还需要最后一步设置,在命令行 ...

  5. Simple上网导航--静态版

    现在的网址导航显然是一个针对小白用户的网页大全,新闻.笑话.视频.黄段子要什么有什么,一个网址导航竟然也要滑动好多页.其实80%的功能我都用不到,但是它们却时刻展现在我的眼前.所以我决定做一个简洁清晰 ...

  6. 获取网站图标Icon

    通常情况下,做网站的都会给自己的网站添加一个Icon,浏览器上一长排的标签页,用Icon来区分就显得更加醒目.现在想找一个没有Icon的网站并不好找,可见没有Icon的网站是多么的业余啊." ...

  7. 【明哥报错簿】之【 "javax.servlet.http.HttpServlet" was not found on the Java Build Path || HttpServletRequest/HttpServletResponse cannot be resolved to a type】

    The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path login ...

  8. 【Java】JAVA-加密-DES加密代码详解

    package util; import java.security.SecureRandom; import javax.crypto.spec.DESKeySpec; import javax.c ...

  9. BZOJ4925 城市规划

    对每个人行道求出移动距离在哪些区间内时其在建筑物前面.现在问题即为选一个点使得其被最多的区间包含.差分即可.对建筑暴力去掉重叠部分.开始时没有去重用了nm次vector的push_back,时间大概是 ...

  10. [HNOI2006]最短母串问题 AC自动机

    题面:洛谷 题解: 如果我们对这些小串建出AC自动机,那么我们所求的大串就是要求满足遍历过所有AC自动机上的叶子节点,且经过步数最少的串.如果有多个步数相同的串,要输出字典序最小的串. 在AC自动机上 ...