[51nod1206]Picture
给你一坨矩形,问这些矩形组成的所有多边形的周长之和。
分别求竖着的边和横着的边。
离散化后线段树,维护当前行(或者列)有多少没在多边形里的,添加矩形就变成添加、删除线段。
每次加线段或删线段时累加一下贡献(加线段时的贡献就是加完后那条线段里有多少个位置变成在多边形里,删线段时的贡献就是删完后有多少个位置变成不在多边形里)。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#define ll long long
#define ull unsigned long long
#define d double
using namespace std;
const int maxn=,mxnode=maxn*;
struct zs{int h,l,r;bool add;}b[maxn];int n1;
struct mat{int x1,y1,x2,y2;}a[];
int lc[mxnode],rc[mxnode],mn[mxnode],num[mxnode],add[mxnode],tot,MX;
int i,j,k,n,m,L,R,V;
ll ans; int ra,fh;char rx;
inline int read(){
rx=getchar(),ra=,fh=;
while((rx<''||rx>'')&&rx!='-')rx=getchar();
if(rx=='-')fh=-,rx=getchar();
while(rx>=''&&rx<='')ra*=,ra+=rx-,rx=getchar();return ra*fh;
} inline void ins(int &x,int l){x=++tot,mn[x]=add[x]=,num[x]=l;}
inline void upd(int x){
int l=lc[x],r=rc[x];
if(mn[l]>mn[r])swap(l,r);
if(mn[l]==mn[r])mn[x]=mn[l]+add[x],num[x]=num[l]+num[r];
else mn[x]=mn[l]+add[x],num[x]=num[l];
}
void insert(int x,int a,int b){
// printf("insert:%d--%d %d-----%d\n",a,b,L,R);
if(L<=a&&R>=b){add[x]+=V,mn[x]+=V;return;}
int mid=a+b>>;
if(!lc[x])ins(lc[x],mid-a+);if(!rc[x])ins(rc[x],b-mid);
if(L<=mid)insert(lc[x],a,mid);
if(R>mid)insert(rc[x],mid+,b);
upd(x);//printf("%d--%d mn:%d num:%d\n",a,b,mn[x],num[x]);
} inline int get0(){return mn[]!=?:num[];}
bool cmp(zs a,zs b){return a.h<b.h||(a.h==b.h&&a.add);}
inline void calc(){
int i;
sort(b+,b++n1,cmp);
for(i=;i<=tot;i++)lc[i]=rc[i]=;tot=,mn[]=add[]=,num[]=MX;
for(i=;i<=n1;i++){
L=b[i].l,R=b[i].r;
if(b[i].add)ans+=get0(),V=,insert(,,MX),ans-=get0();
else ans-=get0(),V=-,insert(,,MX),ans+=get0();//printf("num0:%d mn:%d\n",get0(),mn[1]);
}//printf(" ans:%d\n",ans);
} inline int abs1(int x){return x<?-x:x;}
inline int max(int a,int b){return a>b?a:b;}
int main(){
n=read();int tmp;
for(i=;i<=n;i++){
a[i].x1=read(),a[i].y1=read(),a[i].x2=read()-,a[i].y2=read()-;
tmp=max(max(abs1(a[i].x1),abs1(a[i].x2)),max(abs1(a[i].y1),abs1(a[i].y2)));
if(tmp>MX)MX=tmp;
}
for(i=;i<=n;i++)a[i].x1+=MX+,a[i].x2+=MX+,a[i].y1+=MX+,a[i].y2+=MX+;
MX=MX<<|;
n1=;
for(i=;i<=n;i++)
b[++n1]=(zs){a[i].x1,a[i].y1,a[i].y2,},
b[++n1]=(zs){a[i].x2+,a[i].y1,a[i].y2,};
calc();
n1=;
for(i=;i<=n;i++)
b[++n1]=(zs){a[i].y1,a[i].x1,a[i].x2,},
b[++n1]=(zs){a[i].y2+,a[i].x1,a[i].x2,};
calc();
printf("%lld\n",ans);
}
[51nod1206]Picture的更多相关文章
- 基于Picture Library创建的图片文档库中的上传多个文件功能(upload multiple files)报错怎么解决?
复现过程 首先,我创建了一个基于Picture Library的图片文档库,名字是 Pic Lib 创建完毕后,我点击它的Upload 下拉菜单,点击Upload Picture按钮 在弹出的对话框中 ...
- MFC Picture控件加载图片
CStatic *pPic = (CStatic*)GetDlgItem(IDC_PICTURE); CBitmap bitmap; bitmap.LoadBitmapW(IDB_BITMAP2); ...
- [POJ1177]Picture
[POJ1177]Picture 试题描述 A number of rectangular posters, photographs and other pictures of the same sh ...
- USACO 5.5 Picture(周长并)
POJ最近做过的原题. /* ID: cuizhe LANG: C++ TASK: picture */ #include <cstdio> #include <cstring> ...
- 彩色照片转换为黑白照片(Color image converted to black and white picture)
This blog will be talking about the color image converted to black and white picture. The project st ...
- HDU 1828 Picture(线段树扫描线求周长)
Picture Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- don't forget the bigger picture
Imagine a circle that contains all of human knowledge: By the time you finish elementary school, you ...
- A Complete Guide to the <Picture> Element
If you’ve ever struggled building responsive websites, this post is for you. It’s part of a series o ...
- HDUOJ-----(1162)Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
随机推荐
- python方法的延迟加载
数据挖掘的过程中,数据进行处理是一重要的环节,我们往往会将其封装成一个方法,而有的时候这一个方法可能会被反复调用,每一次都对数据进行处理这将是一个很耗时耗资源的操纵,那么有没有办法将计算后的结果缓存起 ...
- 基于Vue的SPA动态修改页面title的方法
最近基于VUE做个SPA手机端web发现动态修改页面标题通过document.title=xxxx 来修改着实蛋疼,而且在IOS的微信端据说没效果.百度发现要针对IOS的微信做点额外的操作,即:创建一 ...
- Python学习(二):函数入门
1.函数代码格式: def 函数名(): 函数内容 执行函数:函数名() 2.代码举例: #!/usr/bin/env python #coding=utf-8 #定义函数 def Func1(): ...
- 服务器 Python服务停服、起服脚本
近日,在阿里云服务器上部署了一个Python,Web框架为Tornado,服务器为Ubuntu 16.04. 服务的启动也十分的简单: python services.py 我是利用Xshell工具连 ...
- php消息队列之 think queue消息队列初体验
使用thinkphp 5的 消息队列 think queue ● php think queue:listen --queue queuename ● php think queue:work -- ...
- ES6 modules 详解
概述 历史上,JavaScript 一直没有模块(module)体系,无法将一个大程序拆分成互相依赖的小文件,再用简单的方法拼装起来.其他语言都有这项功能,比如 Ruby 的require.Pytho ...
- mac 安装mysql特种报错的对应解决方式
参考 :http://www.jianshu.com/p/776e72742c6e 原文废话太多了, 还是看我的好了. 配置环境变量 echo "export PATH=$PATH:/usr ...
- [js高手之路]html5 canvas动画教程 - 重力、摩擦力、加速、抛物线运动
上节,我们讲了匀速运动,本节分享的运动就更有意思了: 加速运动 重力加速度 抛物线运动 摩擦力 加速运动: <head> <meta charset='utf-8' /> &l ...
- webstorm工具的字体、主题等相关设置
Ctrl + /:单行注释Ctrl + Shift + /:块注释Ctrl + Alt + ↓:向下复制当前行Alt + ↑:向上移动Alt + ↓:向下移动Ctrl + D:删除当前行Ctrl + ...
- Effective Java 第三版——18. 组合优于继承
Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...