题目链接

看的HH的题解。。周长有两部分组成,横着和竖着的,横着通过,sum[1] - last来计算,竖着的通过标记,记录有多少段。

 #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
#define maxn 10000
#define lson l , m, rt<<1
#define rson m+1, r,rt<<1|1
int que[maxn*];
int sum[maxn*];
int cnt[maxn*];
bool lbd[maxn*] , rbd[maxn*];
int numseg[maxn*];
struct node
{
int lx,rx,y;
int s;
node() {}
node(int a,int b,int c,int d):lx(a),rx(b),y(c),s(d) {}
bool operator < (const node &S) const
{
if(y == S.y) return s > S.s;
return y < S.y;
}
} mat[maxn];
int bin(int x,int n)
{
int str,end,mid;
str = ,end = n;
while(str <= end)
{
mid = (str+end)/;
if(que[mid] == x)
return mid;
else if(que[mid] > x)
end = mid - ;
else
str = mid + ;
}
return mid;
}
void pushup(int rt,int l,int r)
{
if(cnt[rt])
{
lbd[rt] = rbd[rt] = ;
sum[rt] = que[r+] - que[l];
numseg[rt] = ;
}
else if (l == r)
{
sum[rt] = numseg[rt] = lbd[rt] = rbd[rt] = ;
}
else
{
lbd[rt] = lbd[rt<<];
rbd[rt] = rbd[rt<<|];
sum[rt] = sum[rt<<] + sum[rt<<|];
numseg[rt] = numseg[rt<<] + numseg[rt<<|];
if (lbd[rt<<|] && rbd[rt<<]) numseg[rt] -= ;
}
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L <= l&&r <= R)
{
cnt[rt] += c;
pushup(rt,l,r);
return ;
}
int m = (l+r)>>;
if(L <= m)
update(L,R,c,lson);
if(R > m)
update(L,R,c,rson);
pushup(rt,l,r);
}
int main()
{
int n,num,i,l,r;
int a,b,c,d;
while(scanf("%d",&n)!=EOF)
{
if(!n) break;
num = ;
for(i = ; i < n; i ++)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
que[num] = a;
mat[num ++] = node(a,c,b,);
que[num] = c;
mat[num ++] = node(a,c,d,-);
}
sort(que,que+num);
sort(mat,mat+num);
int k = ;
for(i = ; i < num; i ++)
{
if(que[i] != que[i-])
que[k++] = que[i];
}
int ans = ,last = ;
memset(cnt,,sizeof(cnt));
memset(sum,,sizeof(sum));
memset(lbd,,sizeof(lbd));
memset(rbd,,sizeof(rbd));
for(i = ; i < num; i ++)
{
l = bin(mat[i].lx,k-);
r = bin(mat[i].rx,k-)-;
if(l <= r)
update(l,r,mat[i].s,,k-,);
ans += numseg[] * (mat[i+].y - mat[i].y);
ans += abs(sum[] - last);
last = sum[];
}
printf("%d\n",ans);
}
return ;
}

POJ 1177 Picture(求周长并)的更多相关文章

  1. HDU 1828 / POJ 1177 Picture (线段树扫描线,求矩阵并的周长,经典题)

    做这道题之前,建议先做POJ 1151  Atlantis,经典的扫描线求矩阵的面积并 参考连接: http://www.cnblogs.com/scau20110726/archive/2013/0 ...

  2. poj 1177 --- Picture(线段树+扫描线 求矩形并的周长)

    题目链接 Description A number of rectangular posters, photographs and other pictures of the same shape a ...

  3. POJ 1177 Picture(线段树周长并)

      描述 A number of rectangular posters, photographs and other pictures of the same shape are pasted on ...

  4. POJ 1177 Picture(线段树:扫描线求轮廓周长)

    题目链接:http://poj.org/problem?id=1177 题目大意:若干个矩形,求这些矩形重叠形成的图形的轮廓周长. 解题思路:这里引用一下大牛的思路:kuangbin 总体思路: 1. ...

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

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

  6. POJ 1177 Picture(线段树 扫描线 离散化 求矩形并面积)

    题目原网址:http://poj.org/problem?id=1177 题目中文翻译: 解题思路: 总体思路: 1.沿X轴离散化建树 2.按Y值从小到大排序平行与X轴的边,然后顺序处理 如果遇到矩形 ...

  7. poj 1177 Picture(线段树周长并)

    题目链接:http://poj.org/problem?id=1177 题意:给你n个矩形问你重叠后外边缘总共多长. 周长并与面积并很像只不过是处理的时候是   增加的周长=abs(上一次的线段的长度 ...

  8. poj 1177 Picture (线段树 扫描线 离散化 矩形周长并)

    题目链接 题意:给出n个矩形,每个矩形给左下 和 右上的坐标,求围成的周长的长度. 分析: 首先感谢大神的博客,最近做题经常看大神的博客:http://www.cnblogs.com/kuangbin ...

  9. poj 1177 picture

    题目链接:http://poj.org/problem?id=1177 分析:这道题主要用到了线段树.扫描线以及离散化的相关算法. 离散化 离散化是当数字不多但是范围很大时采用的一种方法,将大区间的数 ...

随机推荐

  1. 大数据之ETL设计详解

    ETL是BI项目最重要的一个环节,通常情况下ETL会花掉整个项目的1/3的时间,ETL设计的好坏直接关接到BI项目的成败.ETL也是一个长期的过程,只有不断的发现问题并解决问题,才能使ETL运行效率更 ...

  2. Python os.system 和 os.popen的区别

    (1) os.system # 仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息 system(command) -> exit_statusExecute the command ...

  3. 如何让你的scrapy爬虫不再被ban之二(利用第三方平台crawlera做scrapy爬虫防屏蔽)

    我们在做scrapy爬虫的时候,爬虫经常被ban是常态.然而前面的文章如何让你的scrapy爬虫不再被ban,介绍了scrapy爬虫防屏蔽的各种策略组合.前面采用的是禁用cookies.动态设置use ...

  4. 用php计算行列式

    因为有课程设计要计算多元一次方程组,所以想编个程序实现,多元一次方程组的计算最系统的方法就是利用克拉默法则求解方程组,所以只需要编写一个类或者方法求出多元一次方程组系数行列式的值和和其他几个行列式,如 ...

  5. Java for LeetCode 036 Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  6. Java数据类型和运算符

    一,数据类型分类(2种) 1. 基本数据类型(3种) 数值型: 整数类型(4种): byte(1字节):范围(-128~127): short(2字节):范围(-32768~32767): int(4 ...

  7. Tickeys -- 找对打字的感觉 (机械键盘音效软件)

    最近发现公司里面越来越多人开始用机械键盘了,问了很多人为什么用机械键盘,主要有两种,一种是真的情怀,他们怀念十年前那种台式机硬邦邦的键盘,另外一种是因为喜欢机械键盘的声音,打字很爽.前者那真是没救了, ...

  8. Tomcat AccessLog 格式化

    有的时候我们要使用日志分析工具对日志进行分析,需要对日志进行格式化,比如,要把accessLog格式化成这样的格式 c-ip s-ip x-InstancePort date time-taken x ...

  9. QML入门教程

    QML是Qt推出的Qt Quick技术的一部分,是一种新增的简便易学的语言.QML是一种陈述性语言,用来描述一个程序的用户界面:无论是什么样子,以及它如何表现.在QML,一个用户界面被指定为具有属性的 ...

  10. free(): invalid next size (fast/normal)问题

    本文转自 http://blog.sina.com.cn/s/blog_77f1e27f01019qq9.html  ,在此感谢! c++编译常会出现free(): invalid next size ...