题链:http://poj.org/problem?

id=3168

Barn Expansion
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2087   Accepted: 544

Description

Farmer John has N (1 <= N <= 25,000) rectangular barns on his farm, all with sides parallel to the X and Y axes and integer corner coordinates in the range 0..1,000,000. These barns do not overlap although they may share corners and/or sides with other barns. 



Since he has extra cows to milk this year, FJ would like to expand some of his barns. A barn has room to expand if it does not share a corner or a wall with any other barn. That is, FJ can expand a barn if all four of its walls can be pushed outward by at least
some amount without bumping into another barn. If two barns meet at a corner, neither barn can expand. 



Please determine how many barns have room to expand.

Input

Line 1: A single integer, N 



Lines 2..N+1: Four space-separated integers A, B, C, and D, describing one barn. The lower-left corner of the barn is at (A,B) and the upper right corner is at (C,D).

Output

Line 1: A single integer that is the number of barns that can be expanded.

Sample Input

5
0 2 2 7
3 5 5 8
4 2 6 4
6 1 8 6
0 0 8 1

Sample Output

2

Hint

Explanation of the sample: 



There are 5 barns. The first barn has its lower-left corner at (0,2) and its upper-right corner at (2,7), and so on. 



Only two barns can be expanded --- the first two listed in the input. All other barns are each in contact with at least one other barn.

题意:给若干个矩形,直接仅仅有接触,没有重叠。计算出有多少矩形是不和其它矩形有接触。

做法:

把两条横向边和纵向边分解开来。各自存入数组 hh,和ss。

然后排序。以横向为例。先按高度排序,高度同样的 按左边的坐标从小到大排序。

然后for一遍,注意下推断重合时,之前的那个矩形pre也要标记成有接触。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <malloc.h>
#include <ctype.h>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <set>
#include <map> struct point
{
int s,x,id;//下 左 负
int z,y;
point()
{}
point(int _x,int _s,int _z,int _y,int _id)
{
s=_s,x=_x,z=_z,y=_y,id=_id;
}
};
point hh[1000010]; //放横的
point ss[1001000];
int has[26000];
int cmph(point a,point b)
{
if(a.s!=b.s)
return a.s<b.s;
return a.z<b.z;
}
int cmps(point a,point b)
{
if(a.z!=b.z)
return a.z<b.z;
return a.x<b.x;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(has,0,sizeof has);
int h=0;
int s=0;
for(int i=0;i<n;i++)
{
int l,x,r,sh;
scanf("%d%d",&l,&x);
scanf("%d%d",&r,&sh);
hh[h++]=point(x,x,l,r,i);
hh[h++]=point(sh,sh,l,r,i); ss[s++]=point(x,sh,l,l,i);
ss[s++]=point(x,sh,r,r,i);
}
sort(hh,hh+h,cmph);
sort(ss,ss+s,cmps);
int z,y;
int pre;
for(int i=0;i<h;i++)
{
if(i==0)
{
z=hh[i].z;
y=hh[i].y;
pre=hh[i].id;
}
else if(hh[i-1].s==hh[i].s)
{
if(hh[i].z<=y) //在之前的范围内
{
has[pre]=1;
has[hh[i].id]=1;
}
else //不在之前范围内
{
z=hh[i].z;
y=hh[i].y;
pre=hh[i].id;
}
if(hh[i].y>y)//扩展右边
y=hh[i].y;
}
else//不在一个高度时
{
z=hh[i].z;
y=hh[i].y;
pre=hh[i].id;
}
}
int xi,sh;
for(int i=0;i<=s;i++)
{
// printf("x%d s%d l%d id%d\n",ss[i].x,ss[i].s,ss[i].z);
if(i==0)
{
xi=ss[i].x;
sh=ss[i].s;
pre=ss[i].id;
}
else if(ss[i-1].y==ss[i].y)
{
if(ss[i].x<=sh)
{
has[ss[i].id]=1;
has[pre]=1;
}
else
{
xi=ss[i].x;
sh=ss[i].s;
pre=ss[i].id;
}
if(ss[i].s>sh)
sh=ss[i].s;
}
else
{
xi=ss[i].x;
sh=ss[i].s;
pre=ss[i].id;
}
}
int ans=0;
for(int i=0;i<n;i++)
{
if(has[i])
{
// printf("id%d ",i);
ans++;
}
}
printf("%d\n",n-ans);
}
return 0;
}
/*
8 4
4 1 0 0 0 0 1 0
0 0 0 1 0 1 0 0
0 2 1 1 3 0 4 0
0 0 0 4 1 1 1 0
*/

poj 3168 Barn Expansion 几何yy的更多相关文章

  1. POJ 3168 Barn Expansion (几何+排序)

    题目链接:id=3168">POJ 3168 Barn Expansion 题意:抽象出来就是给出n个矩形的坐标是(左下角和右上角的坐标,矩形的边都是平行x,y轴),问有几个矩形和其它 ...

  2. poj 3168 Barn Expansion

    Barn Expansion Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2465   Accepted: 666 Des ...

  3. POJ 3168 Barn Expansion (几何基础)

    [题目链接] http://poj.org/problem?id=3168 [题目大意] 给出一些矩形,没有相交和包含的情况,只有相切的情况 问有多少个矩形没有相切或者边角重叠 [题解] 我们将所有的 ...

  4. poj 3233 矩阵快速幂+YY

    题意:给你矩阵A,求S=A+A^1+A^2+...+A^n sol:直接把每一项解出来显然是不行的,也没必要. 我们可以YY一个矩阵: 其中1表示单位矩阵 然后容易得到: 可以看出这个分块矩阵的左下角 ...

  5. poj 3734 矩阵快速幂+YY

    题目原意:N个方块排成一列,每个方块可涂成红.蓝.绿.黄.问红方块和绿方块都是偶数的方案的个数. sol:找规律列递推式+矩阵快速幂 设已经染完了i个方块将要染第i+1个方块. a[i]=1-i方块中 ...

  6. poj3168 Barn Expansion【计算几何 平面扫描】

    Farmer John has N (1 <= N <= 25,000) rectangular barns on his farm, all with sides parallel to ...

  7. POJ 2546 Circular Area 几何

    http://poj.org/problem?id=2546 晚上发现鼠标快不行了了!!!鼠标你肿么了,肿么突然就按键不灵了,哭,谁送我一只呀,奖励我舍友一只.哈哈.开玩笑滴~ 舍友大怒说" ...

  8. POJ - 1127 Jack Straws(几何)

    题意:桌子上放着n根木棍,已知木棍两端的坐标.给定几对木棍,判断每对木棍是否相连.当两根木棍之间有公共点或可以通过相连的木棍间接的连在一起,则认为是相连的. 分析: 1.若线段i与j平行,且有部分重合 ...

  9. poj 1701【数学几何】

    The area Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

随机推荐

  1. python基础知识——基于python3.6

    语法糖 # # -*- coding: utf-8 -*- # #------------- # #--------- 语法糖--------------- # #------------------ ...

  2. 阿里云ecs初始化磁盘后远程连接不到服务器

    阿里云初始化磁盘后远程连接不到服务器 报错: WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! ... 原因:阿里云ecs第一次链接服务器之后会在本地电 ...

  3. 一、VueJs 填坑日记之基础概念知识解释

    概述在最开始听说vuejs这个词是在2016年,当时天真的认为自己是个后端开发工程师不需要学习太多的前端知识,不过紧接着在2017年在公司就用到了vuejs.对于初学者(尤其是干后端的初学者)来说,刚 ...

  4. 一:MySQL数据库的性能的影响分析及其优化

    MySQL数据库的性能的影响分析及其优化 MySQL数据库的性能的影响 一. 服务器的硬件的限制 二. 服务器所使用的操作系统 三. 服务器的所配置的参数设置不同 四. 数据库存储引擎的选择 五. 数 ...

  5. 《Linux命令行与shell脚本编程大全》第十章 使用编辑器

    主要介绍vim, nano, emacs,KWrite,Kate,GNOME 10.1 vim Unix系统最初的编辑器 10.1.1检查vim软件包 先搞明白你所用的Linux系统是哪种vim软件包 ...

  6. KICKSTART无人值守安装 - (字符界面操作)

    kickstart 部署 1.1 kickstart简介说明 1.1.1 pxe工作过程(图) 1.1.2 kickstart具体过程(图) 1.2 kickstart无人值守部署 1.2.1 系统环 ...

  7. 浅谈Verilog HDL代码编写风格

    消失了好久,没有写文章,也没有做笔记,因为最近再赶一个比赛,时间很紧,昨天周六终于结束了,所以趁着周末这会儿有时间,写点东西,记录下来.首先我学习FPGA才一年多,我知道自己没有资格谈论一些比较深层次 ...

  8. Python进阶---面向对象第二弹

    python类的继承原理 一.类的继承顺序 class A(object): def test(self): print('from A') passclass B(A): # def test(se ...

  9. Python之数据类型-[bisect,heap]

    bisect >>> import bisect >>> >>> b = [ 20, 34, 35, 65, 78 ] >>> ...

  10. one 策略模式 strategy

    --读书笔记 定义 策略模式--定义算法簇,分别封装起来,让他们之间可以互相替换,此模式让算法的变化独立于使用算法的客户.(看不懂的话,往下,有人话版/我自己的解释) 相关原则 > 1,变化单独 ...