哇!这小破题坑了我好久。

扫描线+线段树

这题数据范围小,没离散化。真要离散化我还搞不好呢。

具体的看这个博客吧。

主要是这个坑爹的c,len把我搞了,其他的还好。

代码:

 #include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
struct Node
{
int len,s;
} node[];
struct Edge
{
int L,R,high,flag;
bool operator < (const Edge &a) const
{
if(this->high!=a.high)return this->high>a.high;
return this->flag<a.flag;
}
};
priority_queue<Edge>x;
priority_queue<Edge>y;
void build(int l,int r,int o)
{
node[o].len=;
node[o].s=;
if(l==r) return;
int mid=(l+r)>>;
build(l,mid,o<<);
build(mid+,r,o<<|);
return;
}
void up(int l,int r,int o)
{
if(node[o].s) node[o].len=r-l+;
else if(l==r) node[o].len=;
else node[o].len=node[o<<].len+node[o<<|].len;
return;
}
void add(int L,int R,int v,int l,int r,int o)
{
//printf("add:%d %d %d %d %d %d\n",L,R,v,l,r,o);
if(L<=l && r<=R)
{
node[o].s+=v;
up(l,r,o);
return;///这里的return一开始忘了打,死循环。
}
if(R<l || r<L) return;
int mid=(l+r)>>;
if(L<=mid) add(L,R,v,l,mid,o<<);
if(mid<R) add(L,R,v,mid+,r,o<<|);
up(l,r,o);
return;
}
void adde(int x1,int y1,int x2,int yyy)
{
Edge xup,xlow,yup,ylow;
xup.L=xlow.L=ylow.high=x1;
xup.R=xlow.R=yup.high=x2;
yup.L=ylow.L=xlow.high=y1;
yup.R=ylow.R=xup.high=yyy;
xlow.flag=ylow.flag=;
xup.flag=yup.flag=-;
//printf("adde:%d %d %d %d\n",xup.L,xup.R,xup.high,xup.flag);
//printf("adde:%d %d %d %d\n",xlow.L,xlow.R,xlow.high,xlow.flag);
x.push(xup);
x.push(xlow);
y.push(yup);
y.push(ylow);
return;
}
int main()
{
int N = ;
build(,N,);
int n,x1,x2,y1,yyy;
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&yyy);///这里 的变量名传错了,0分
adde(x1+,y1+,x2+,yyy+);
}
Edge e;int len=;
long long int ans=;
while(!x.empty())
{
//printf("x\n");
e=x.top();
x.pop();
//printf("edge:%d %d %d %d\n",e.L,e.R,e.high,e.flag);
add(e.L,e.R-,e.flag,,N,);
ans+=abs(node[].len-len);
len=node[].len;
//printf("ans=%d\n",ans);
}
build(,N,);len=;
while(!y.empty())
{
//printf("y\n");
e=y.top();
//printf("edge:%d %d %d %d\n",e.L,e.R,e.high,e.flag);
y.pop();
add(e.L,e.R-,e.flag,,N,);
ans+=abs(node[].len-len);
len=node[].len;
//printf("ans=%d\n",ans);
}
printf("%lld",ans);
return ;
}
/**
4
1 1 2 2
3 1 5 3
4 0 6 2
5 -1 7 1 20
*/

洛谷的数据好水

还有更高级的方法我没搞了,晦涩难懂......

P1856 矩形周长的更多相关文章

  1. P1856 [USACO5.5]矩形周长Picture

    P1856 [USACO5.5]矩形周长Picture $len$            $sum$              $num$             $flag\_l$ $flage\_ ...

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

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

  3. 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( ...

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

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

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

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

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

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

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

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

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

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

  9. POJ 1177 矩形周长并 模板

    Picture 题目链接 http://poj.org/problem?id=1177 Description A number of rectangular posters, photographs ...

随机推荐

  1. 如何使用chrome浏览器进行js调试找出元素绑定的点击事件

    大家有没有遇到这样的一个问题,我们在分析一些大型电子商务平台的Web前端脚本时,想找到一个元素绑定的点击事件,并不是那么容易,因为有些前端脚本封装的比较隐蔽,甚至有些加密脚本,用传统的查找元素ID.或 ...

  2. SQL行转列汇总 (转)

    PIVOT 用于将列值旋转为列名(即行转列),在 SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT 的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )A ...

  3. 算法模板学习专栏之总览(会慢慢陆续更新ing)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/7495310.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  4. js格式化时间

    转自:https://blog.csdn.net/u010964869/article/details/51095827 显示格式为:yyyy-mm-dd hh:mi:ss function form ...

  5. Pairproject 移山之道 阅读随笔和一些问题

    首先不得不承认这本书的写作方式很独特,不像其他的计算机类的图书那样枯燥,让人读起来感觉很有意思,他也颠覆了我对计算机类图书的看法,这种写作方式值得我们学习. 先谈谈收获吧.读了两年大学,这是第一次写类 ...

  6. Anaconda2和Anaconda3同时安装

    转载于:https://www.cnblogs.com/zle1992/p/6720425.html 1.先从网站(国内的清华镜像:https://mirrors.tuna.tsinghua.edu. ...

  7. SQL Data Compare 对比 SQLserver数据

    1. 下载redgate的工具 https://www.red-gate.com/dynamic/products/sql-development/sql-compare/download 2. 输入 ...

  8. vCenter简单查看多少虚拟机在开机状态和一共多少虚拟机

    vCenter 界面上面不好找 具体的开机 运行数目 但是数据库里面比较好差 登录vCenter的数据库. 查看表主要是 查看正在开机的虚拟机 select * from dbo.VPX_VM WHE ...

  9. 堆排序获取TopN

    package com.zjl.tool.sort; /** * 求前面的最大K个 解决方案:小根堆 (数据量比较大(特别是大到内存不可以容纳)时,偏向于采用堆) * @author 张恩备 * @d ...

  10. Angular @的作用

    <!DOCTYPE html><html lang="zh-cn" ng-app="myApp"><head> <me ...