[51nod1206]Picture

时间:2021-12-24 20:05:32

  给你一坨矩形,问这些矩形组成的所有多边形的周长之和。

  分别求竖着的边和横着的边。

  离散化后线段树,维护当前行(或者列)有多少没在多边形里的,添加矩形就变成添加、删除线段。

  每次加线段或删线段时累加一下贡献(加线段时的贡献就是加完后那条线段里有多少个位置变成在多边形里,删线段时的贡献就是删完后有多少个位置变成不在多边形里)。

 #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的更多相关文章

  1. 基于Picture Library创建的图片文档库中的上传多个文件功能&lpar;upload multiple files&rpar;报错怎么解决?

    复现过程 首先,我创建了一个基于Picture Library的图片文档库,名字是 Pic Lib 创建完毕后,我点击它的Upload 下拉菜单,点击Upload Picture按钮 在弹出的对话框中 ...

  2. MFC Picture控件加载图片

    CStatic *pPic = (CStatic*)GetDlgItem(IDC_PICTURE); CBitmap bitmap; bitmap.LoadBitmapW(IDB_BITMAP2); ...

  3. &lbrack;POJ1177&rsqb;Picture

    [POJ1177]Picture 试题描述 A number of rectangular posters, photographs and other pictures of the same sh ...

  4. USACO 5&period;5 Picture&lpar;周长并&rpar;

    POJ最近做过的原题. /* ID: cuizhe LANG: C++ TASK: picture */ #include <cstdio> #include <cstring&gt ...

  5. 彩色照片转换为黑白照片&lpar;Color image converted to black and white picture&rpar;

    This blog will be talking about the color image converted to black and white picture. The project st ...

  6. HDU 1828 Picture(线段树扫描线求周长)

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

  7. don&&num;39&semi;t forget the bigger picture

    Imagine a circle that contains all of human knowledge: By the time you finish elementary school, you ...

  8. A Complete Guide to the &lt&semi;Picture&gt&semi; Element

    If you’ve ever struggled building responsive websites, this post is for you. It’s part of a series o ...

  9. HDUOJ-----&lpar;1162&rpar;Eddy&&num;39&semi;s picture(最小生成树)

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

随机推荐

  1. TCP连接建立和终止小结

    TCP连接建立(三次握手) 如图: 请求端发送一个SYN到服务器的相应端口,以及初始序号ISN 服务器发送包含服务器的初始序号的SYN作为应答,同时确认序号设置为客户的ISN+1 客户将确认序号设置为 ...

  2. redis 操作 list 的测试

    lpush 从头部压入数据 127.0.0.1:6379> lpush listname value1 (integer) 1//返回list的当前长度 127.0.0.1:6379> l ...

  3. redis 下载启动,设置、查询超时时间

    1.定义 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted ...

  4. Mininet实验 源码安装Mininet

    参考:MiniNet实验1 安装命令: sudo apt-get update sudo apt-get upgrade sudo apt-get install git(安装过git就可以忽略此步) ...

  5. java基础-关键字-native

     一. 什么是Native Method    简单地讲,一个Native Method就是一个java调用非java代码的接口.一个Native Method是这样一个java的方法:该方法的实现由 ...

  6. WPF界面设计

    WPF仿360卫士9.0界面设计   Chrome插件——一键保存网页为PDF1.0 http://www.cnblogs.com/bdstjk/p/3163723.html 仿照网上的一个代码写的, ...

  7. 【温故而知新】HTTP 概述

    什么是 HTTP 官方解释是 "因特网的多媒体信使",通俗点说,就是个送信的.电话机出来之前,人与人(有一定距离)之间的沟通基本靠写信,然后由快递员送发.如果把 web 服务器和客 ...

  8. Workspace in use or cannot be created&comma; choose a different one&period;

      eclipse 使用一段时间后,有时会因为一些故障自己就莫名奇妙的关闭了,再打开时有时没有问题,有时有会提示错误 Workspace Unavailable: Workspace in use o ...

  9. JS级联下拉框

    //Ajax级联获取SDKfunction GetDropDownList(parent_ddlID, fill_dllID, url, param) {    this.pId = parent_d ...

  10. 关于ORM,以及Python中SQLAlchemy的sessionmaker,scoped&lowbar;session

    orm(object relational mapping):对象关系映射. python面向对象,而数据库是关系型. orm是将数据库关系映射为Python中的对象,不用直接写SQL. 缺点是性能略 ...