[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 ...
随机推荐
- 解读JavaScript原型链
var F = function(){}; F.prototype.a = function(){}; Object.prototype.b = function(){}; Function.prot ...
- 解决author波浪线Spellchecker inspection helps locate typos and misspelling in your code, comments and literals, and fix them in one click
自从把默认的头注释的author改成自己的名字以后越看越顺眼,但是发现名字下面一直有个波浪线,强迫症简直不能忍. 然后当你把鼠标放上去,再点击提示上的"more",会看到下面的提示 ...
- xamarin Android activity生命周期详解
学Xamarin我为什么要写这样一篇关于Android 的activity生命周期的文章 已经学Xamarin android有一段时间了,现在想起当初Xamarin也走了不少的弯路.当然Xamari ...
- bzoj 3932: [CQOI2015]任务查询系统
Description 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si ...
- 文件上传之伪Ajax方式上传
From: <由 Windows Internet Explorer 8 保存> Subject: =?gb2312?B?zsS8/snPtKvWrs6xQWpheLe9yr3Jz7SrI ...
- PHP-CGI进程占用过多CPU
一般情况下,PHP-CGI只在用户访问的时候会占用CPU资源,但是最近有同事反映,服务器上的的PHP-CGI进程占用了非常多的CPU,但是访问流量却非常少.这显然是一个不正常的现象,说有些地方存在故障 ...
- Django2文档-入门概览
Django 概览 Django 是设计是为了使通用的Web开发任务变得快速而又简单, 一下是如何使用Django编写数据库驱动的Web应用程序的非正式概述. 这个文档的目标是给你足够的技术细节来理解 ...
- TCP协议(二)——TIME_WAIT状态
当TCP主动关闭套接字时,采用四步握手机制来彻底关闭连接.如图: 客户端主动关闭连接,发送FIN段到服务端.TCP状态由ESTABLISHED(连接状态)转为FIN_WAIT1(表示,发送的FIN需要 ...
- vlc源码研究
有位传说中的大神告诉我,我的p2p打洞打不通是因为,sdp描述信息中的地址不对 也就是IN IP4 XXX.XXX.X.XXX这一句 我看到确实是个局域网地址,那么vlc在接收到IN IP4 XXX. ...
- Node.js 蚕食计划(二)—— 使用 http 模块搭建 Web 服务器
Node.js 开发的目的就是为了用 JavaScript 编写 Web 服务器程序 这次就来介绍用 http 模块搭建服务器 一.项目构建 每个 Node 程序都可以看作一个模块,而每个模块都应该有 ...