/*
暴力应该很好理解 不多说了
至于线段树维护的嘛 还没看懂
哪天突然想明白了在写吧
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 5010
#define bas 10000
using namespace std;
int n,m,f[maxn*],ans;
struct node{
int l,r,h,t;
}A[maxn*],B[maxn*];
int cmp(const node &a,const node &b){
if(a.h==b.h)return a.t<b.t;
return a.h<b.h;
}
int main()
{
freopen("picture.in","r",stdin);
freopen("picture.out","w",stdout);
scanf("%d",&n);
int x1,x2,y1,y2;
for(int i=;i<=n;i++){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1+=bas;x2+=bas;y1+=bas;y2+=bas;
A[++m].l=x1;A[m].r=x2;A[m].h=y1;A[m].t=;
B[m].l=y1;B[m].r=y2;B[m].h=x1;B[m].t=;
A[++m].l=x1;A[m].r=x2;A[m].h=y2;A[m].t=;
B[m].l=y1;B[m].r=y2;B[m].h=x2;B[m].t=;
}
sort(A+,A++m,cmp);sort(B+,B++m,cmp);
for(int i=;i<=m;i++){
int l=A[i].l,r=A[i].r;
for(int j=l;j<r;j++){
if(A[i].t==){if(f[j]==)ans++;f[j]++;}
else{f[j]--;if(f[j]==)ans++;}
}
}
memset(f,,sizeof(f));
for(int i=;i<=m;i++){
int l=B[i].l,r=B[i].r;
for(int j=l;j<r;j++){
if(B[i].t==){if(f[j]==)ans++;f[j]++;}
else{f[j]--;if(f[j]==)ans++;}
}
}
printf("%d\n",ans);
}

codevs 2149 矩形周长(暴力扫描线)的更多相关文章

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

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

  2. luogu P1856 [USACO5.5]矩形周长Picture 扫描线 + 线段树

    Code: #include<bits/stdc++.h> #define maxn 200007 #define inf 100005 using namespace std; void ...

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

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

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

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

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

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

  6. 扫描线矩形周长的并 POJ1177

    //扫描线矩形周长的并 POJ1177 // 我是按x轴 #include <iostream> #include <cstdio> #include <cstdlib& ...

  7. HDU 1828“Picture”(线段树+扫描线求矩形周长并)

    传送门 •参考资料 [1]:算法总结:[线段树+扫描线]&矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) •题意 给你 n 个矩形,求矩形并的周长: •题解1(两次扫描线) 周 ...

  8. hdu1828 Picture(线段树+扫描线+矩形周长)

    看这篇博客前可以看一下扫描线求面积:线段树扫描线(一.Atlantis HDU - 1542(覆盖面积) 二.覆盖的面积 HDU - 1255(重叠两次的面积))  解法一·:两次扫描线 如图我们可以 ...

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

随机推荐

  1. 把Blob 转化为字符串查询。

    在Oracle里面,有时候我们对于clob或者是blob作为varhcar2来查询. Clob可以直接使用 to char函数来转换. Blob就需要用 UTL_RAW.CAST_TO_VARCHAR ...

  2. 写个自动安装JDK的shell脚本

    #!/bin/bash ################################################# # # INSTALL JDK AUTOMATICALLY # # auth ...

  3. 获取设备mac地址和md5加密

    SGMSettingConfig.h #import <Foundation/Foundation.h> @interface SGMSettingConfig : NSObject{ N ...

  4. 【POJ1284】Primitive Roots 欧拉函数

    题目描述: 题意: 定义原根:对于一个整数x,0<x<p,是一个mod p下的原根,当且仅当集合{ (xi mod p) | 1 <= i <= p-1 } 等于{ 1, .. ...

  5. javascript中神奇的(+)加操作符

    javascript是一门神奇的语言,这没神奇的语言中有一个神奇的加操作符. 常用的加操作符我们可以用来做: 加法运算,例如:alert(1+2); ==>3 字符串连接,例如:alert(“a ...

  6. struts2中获取request、response,与android客户端进行交互(文件传递给客户端)

    用struts2作为服务器框架,与android客户端进行交互需要得到request.response对象. struts2中获取request.response有两种方法. 第一种:利用Servle ...

  7. 关于android布局的两个属性dither和tileMode

    首先,两个单词的中文意思分别是dither(抖动)和tileMode(平铺) 1,先来介绍tileMode(平铺) 它的效果类似于 让背景小图不是拉伸而是多个重复(类似于将一张小图设置电脑桌面时的效果 ...

  8. Hosting Multiple Service Implementations On The Same Port With WCF

    Hosting Multiple Service Implementations On The Same Port With WCF Recently I have been playing arou ...

  9. Google Map API 学习六-设置infoWindow的长宽

  10. python中文乱码例子

    #coding=utf-8 #---中文乱码--- #直接打印中文 print '千里之外取人首级,瞬息之间爆人菊花.' #中文前面加u,变成Unicode编码 print u'千里之外取人首级' # ...