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

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. DEBUG_NEW和THIS_FILE

    C++ 的一个 比较晦涩难懂的特点是你可以重载 new 操作符,并且你甚至可以给它附加参数.通常,操作符 new 只接受拟分配对象的大小:        void* operator new(size ...

  2. iptables 工具的使用

    试验建议:关闭CentOS 7 或 CentOS 6的防火墙 (systemctl stop firewalld ; systemctl disable firewalld 或 service ipt ...

  3. CCF——数位之和201512-1

    问题描述 给定一个十进制整数n,输出n的各位数字之和. 输入格式 输入一个整数n. 输出格式 输出一个整数,表示答案. 样例输入 20151220 样例输出 13 样例说明 20151220的各位数字 ...

  4. QMap使用

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QMap使用     本文地址:https://www.techieliang.com/201 ...

  5. 1st 英文文章词频统计

    英文文章词频统计: 功能:统计一篇英文文章的单词总数及出现频数并输出,之后排序,输出频数前十的单词及其频数. 实现方法:使用C语言,用fopen函数读入txt文件,fscanf函数逐个读入单词,结构体 ...

  6. Kafka集群无法外网访问问题解决攻略

    Kafka无法集群外网访问问题解决方法  讲解本地消费者和生产者无法使用远程Kafka服务器的处理办法 服务搭建好Kafka服务后,机本.测试 OK,外面机器却无法访问,很是怪异. 环境说明:  Ka ...

  7. 【.Net】HttpClient 的使用

    class Program { public static HttpClient Client; static HttpResponseMessage response; static void Ma ...

  8. 【bzoj3796】Mushroom追妹纸 Kmp+二分+Hash

    题目描述 给出字符串s1.s2.s3,找出一个字符串w,满足: 1.w是s1的子串: 2.w是s2的子串: 3.s3不是w的子串. 4.w的长度应尽可能大 求w的最大长度. 输入 输入有三行,第一行为 ...

  9. 【数据库_Mysql】查询当前年份的sql

    1.本年份 SELECT DATE_FORMAT(NOW(), '%Y'); 2.本月份(显示数字) SELECT DATE_FORMAT(NOW(), '%m'); 3.本月份(显示英文) SELE ...

  10. Unity3D手游开发日记(5) - 适合移动平台的植被随风摆动

    一直在思考怎么让场景更有生机,我觉得植被的随风摆动是必不可少的.CE3引擎的植被bending就做得特别棒.我也准备在手机上做一套. 先分析一下植被摆动常见的几种做法.其实不管哪种做法,核心就是让植被 ...