//扫描线矩形周长的并 POJ1177
// 我是按x轴 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
// #include <memory.h>
// #include <bits/stdc++.h>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const LL inf = 0x3f3f3f3f;
const LL MOD =100000000LL;
const int N = ;
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} struct node{
int x1,x2,y;
int flag;
bool operator < (const node &a) const{
return y<a.y||(y==a.y&&flag>a.flag);
}
}e[N<<]; int color[N<<];
int sum[N<<],hashh[N<<];
int cnt[N<<],pl[N<<],pr[N<<];
void pushup(int rt,int l,int r){
if(color[rt]) {
sum[rt]=hashh[r+]-hashh[l];
cnt[rt]=;
pl[rt]=pr[rt]=;
}
else if(l!=r) {
sum[rt]=sum[rt<<]+sum[rt<<|];
cnt[rt]=cnt[rt<<]+cnt[rt<<|]-(pr[rt<<]&&pl[rt<<|]);
pr[rt]=pr[rt<<|];
pl[rt]=pl[rt<<];
}
else sum[rt]=cnt[rt]=pl[rt]=pr[rt]=;
}
void update(int l,int r,int L,int R,int rt,int f){
if(l<=L&&R<=r){
color[rt]+=f;
pushup(rt,L,R);
return;
}
int mid=(L+R)>>;
if(l<=mid) update(l,r,L,mid,rt<<,f);
if(r>mid) update(l,r,mid+,R,rt<<|,f);
pushup(rt,L,R);
} int main(){
// fre();
int n;
scanf("%d",&n);
memset(color,,sizeof(color));
memset(sum,,sizeof(sum));
memset(cnt,,sizeof(cnt));
memset(pr,,sizeof(pr));
memset(pl,,sizeof(pl));
int x1,x2,y1,y2;
for(int i=;i<=n;i++){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
e[i*-].x1=e[i*].x1=x1;
e[i*-].x2=e[i*].x2=x2;
e[i*-].y=y1,e[i*].y=y2;
e[i*-].flag=,e[i*].flag=-;
hashh[i*-]=x1,hashh[i*]=x2;
}
sort(e+,e++*n);
sort(hashh+,hashh++*n);
int ans=;
int lastsum=;
e[].y=e[].y;
for(int i=;i<=*n;i++){
ans+=(e[i].y-e[i-].y)**cnt[];
int l=lower_bound(hashh+,hashh++*n,e[i].x1)-hashh;
int r=lower_bound(hashh+,hashh++*n,e[i].x2)-hashh-;
if(l<=r) update(l,r,,*n,,e[i].flag);
ans+=abs(sum[]-lastsum);
lastsum=sum[];
}
printf("%d\n",ans);
return ;
}

扫描线矩形周长的并 POJ1177的更多相关文章

  1. hdu 1828 Picture(线段树扫描线矩形周长并)

    线段树扫描线矩形周长并 #include <iostream> #include <cstdio> #include <algorithm> #include &l ...

  2. hdu1828 Picture(线段树+扫描线+矩形周长)

    看这篇博客前可以看一下扫描线求面积:线段树扫描线(一.Atlantis HDU - 1542(覆盖面积) 二.覆盖的面积 HDU - 1255(重叠两次的面积))  解法一·:两次扫描线 如图我们可以 ...

  3. HDU 1828 扫描线(矩形周长并)

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  4. 51nod 1206 Picture 矩形周长求并 | 线段树 扫描线

    51nod 1206 Picture 矩形周长求并 | 线段树 扫描线 #include <cstdio> #include <cmath> #include <cstr ...

  5. P1856 [USACO5.5]矩形周长Picture[扫描线]

    题目背景 墙上贴着许多形状相同的海报.照片.它们的边都是水平和垂直的.每个矩形图片可能部分或全部的覆盖了其他图片.所有矩形合并后的边长称为周长. 题目描述 编写一个程序计算周长. 如图1所示7个矩形. ...

  6. HDU 1828“Picture”(线段树+扫描线求矩形周长并)

    传送门 •参考资料 [1]:算法总结:[线段树+扫描线]&矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) •题意 给你 n 个矩形,求矩形并的周长: •题解1(两次扫描线) 周 ...

  7. 25.按要求编写一个Java应用程序: (1)编写一个矩形类Rect,包含: 两个属性:矩形的宽width;矩形的高height。 两个构造方法: 1.一个带有两个参数的构造方法,用于将width和height属性初化; 2.一个不带参数的构造方法,将矩形初始化为宽和高都为10。 两个方法: 求矩形面积的方法area() 求矩形周长的方法perimeter() (2)通过继承Rect类编写一个具有

    package zhongqiuzuoye; //自己写的方法 public class Rect { public double width; public double height; Rect( ...

  8. HDU 1828 / POJ 1177 Picture --线段树求矩形周长并

    题意:给n个矩形,求矩形周长并 解法:跟求矩形面积并差不多,不过线段树节点记录的为: len: 此区间线段长度 cover: 此区间是否被整个覆盖 lmark,rmark: 此区间左右端点是否被覆盖 ...

  9. HDU 6362(求椭圆中矩形周长的期望 数学)

    题意是给定一个椭圆标准方程的a,b(椭圆的长半轴长和短半轴长),在[0,b]内取一个数,则过点(0,b)且平行于x轴的直线与椭圆交于两点,再将此两点关于x轴做对称点,顺次连接此四点构成矩形,求出这些矩 ...

随机推荐

  1. ReadyAPI创建功能测试的多种方法

    原文:ReadyAPI创建功能测试的多种方法 声明:如果你想转载,请标明本篇博客的链接,请多多尊重原创,谢谢! 本篇使用的 ReadyAPI版本是2.5.0 在ReadyAPI中有多种方法可以创建功能 ...

  2. JS数组 一起组团(什么是数组)一个数组变量可以存放多个数据

    一起组团(什么是数组) 我们知道变量用来存储数据,一个变量只能存储一个内容.假设你想存储10个人的姓名或者存储20个人的数学成绩,就需要10个或20个变量来存储,如果需要存储更多数据,那就会变的更麻烦 ...

  3. Python中死锁的形成示例及死锁情况的防止

    死锁示例搞多线程的经常会遇到死锁的问题,学习操作系统的时候会讲到死锁相关的东西,我们用Python直观的演示一下.死锁的一个原因是互斥锁.假设银行系统中,用户a试图转账100块给用户b,与此同时用户b ...

  4. 廖雪峰Java11多线程编程-3高级concurrent包-4Concurrent集合

    Concurrent 用ReentrantLock+Condition实现Blocking Queue. Blocking Queue:当一个线程调用getTask()时,该方法内部可能让给线程进入等 ...

  5. Config程序配置文件(configSections)操作实践及代码详注

    所有与配置文件相关的类:(粗体为一般情况下使用到的类,其它类功能可能在很复杂的情况下才使用到.) 1.ConfigurationManager,这个提供用于打开客户端应用程序集的Configurati ...

  6. 反编译之jadx工具

    1.jadx是个开源 https://github.com/skylot/jadx 2.下载后cd到文件的根目录 然后输入命令 ./gradlew dist 之后会出现build文件进入/build/ ...

  7. CF #578 Div2

    // 比赛链接:https://codeforces.com/contest/1200 A - Hotelier 题意: 有一家旅馆有10间房,编号0~9,从左到右顺序排列.旅馆有左右两扇门,每次新来 ...

  8. C#Image和Icon的相互转化

    Image img = Image.FromHbitmap(icon.ToBitmap().GetHbitmap()); Graphics g = Graphics.FromImage(img); g ...

  9. vue页面刷新数据丢失问题

    参考: https://blog.csdn.net/aliven1/article/details/80743470          https://blog.csdn.net/liang37712 ...

  10. 在HBase之上构建SQL引擎