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

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.

 
题意:二维坐标给定N块矩阵,如果其中某块矩阵与其他任意一块矩阵有接触的话(边或者顶点有接触),那么这块矩阵就无法扩充,问到底有多少矩阵是可以扩充的。
思路:分别用平行于y轴和x轴方向的直线扫描平面。具体做法,现在不妨用平行于y轴的直线来扫描平面,扫描到如下情况时,我们首先给所有顶点编号,不妨从下往上编,这样就得从下往上考虑,如果当前考虑到的顶点是一个矩阵一条边的起始点,那么记录器num++,
遇到的顶点是一条边的终点,num--,表示这条边不会再和接下来的矩阵存在重叠的关系。如果遇到了某个起始点,num++后num的值大于等于2,说明这个顶点左右两边的矩阵一定是有接触的(意味着一条边还没走到终点又碰到了一个起始点,那么这两条边就就有一部分重叠在了一起),例如图中,先碰到了顶点1,后来又碰到了顶点2,那么之后那部分的边就是左右矩阵所公用的。那么遇到一个终点,num--后num==0,说明这个终点之后的顶点就不能和之前的矩阵有公共边的关系了。

AC代码:

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
const int N_MAX =+ ;
int N; enum point_type{
START, END
};
struct P {
int x, y;
int id;//坐标点是属于第几个矩形的
point_type type;
P(int x,int y,int id,point_type type):x(x),y(y),id(id),type(type) {}
bool operator <(const P&b)const {
if (x != b.x)return x < b.x;
else if (y != b.y)return y < b.y;
else return type < b.type;
}
};
//P p1[N_MAX], p2[N_MAX];
vector<P>p1;
vector<P>p2;
bool ok[N_MAX];
void scan( vector<P>p1) {
vector<P>::iterator it = p1.begin();
int connect_num = ;
int cur_x = it->x;
bool illegal = ;
while (it!=p1.end()) {
if (cur_x != it->x) {//扫描到了新的一列上
connect_num = ;
cur_x = it->x;
illegal = ;
}
int cur_y = it->y;
while (it!=p1.end()&&cur_x==it->x&&cur_y==it->y) {//处理同一个坐标点或者同一列上的坐标点
if (illegal)ok[it->id] = true;//这个点重合了
if (it->type == START) {
connect_num++;
if (connect_num >= )illegal = true;//按y坐标向上扫描扫描到某个顶点开始有边或者点重合了,那么两边的矩阵都不能扩展了
}
if (it->type == END) {
connect_num--;
if (connect_num == )illegal = false;
}
it++;
} }
}
void clear() {
p1.clear();
p2.clear();
}
int main() {
while (scanf("%d",&N)!=EOF) {
for (int i = ;i<N;i++) {
int A,B,C,D;
scanf("%d%d%d%d",&A,&B,&C,&D);
p1.push_back(P(A, B, i, START));
p1.push_back(P(C, B, i, START));
p1.push_back(P(A,D,i,END));
p1.push_back(P(C, D, i, END));
p2.push_back(P(B,A,i,START));
p2.push_back(P(D,A,i,START));
p2.push_back(P(B,C,i,END));
p2.push_back(P(D, C, i, END));
}
sort(p1.begin(), p1.end());
sort(p2.begin(),p2.end());
memset(ok, , sizeof(ok));
scan(p1);
scan(p2);
printf("%d\n", count(ok, ok + N,false));
clear();
}
return ;
}

poj 3168 Barn Expansion的更多相关文章

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

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

  2. poj 3168 Barn Expansion 几何yy

    题链:http://poj.org/problem? id=3168 Barn Expansion Time Limit: 1000MS   Memory Limit: 65536K Total Su ...

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

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

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

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

  5. POJ 3168 排序+扫描

    题意: 思路: 我们可以把每个矩形拆成四条线 与x轴平行的放在一起 与y轴平行的放在一起 排个序 判一判有没有交 有交 则说明不可扩张 统计一下 就可以了 处理的姿势很重要 姿势不对毁一生 //By ...

  6. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  7. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  8. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

  9. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

随机推荐

  1. javascript 完整知识点整理

    by 蔡舒啸 目录 一 5种基本类型 typeof 关键字 三种强制类型转换 日期 二 if语句for语句whiledo-whileswitch-case 比较运算符 逻辑运算符 if for语句 w ...

  2. MySQL Innodb表空间不足的处理方法

    官方给出的解决方案: 添加和删除 InnoDB 数据和日志文件 这一节描述在InnoDB表空间耗尽空间之时,或者你想要改变日志文件大小之时,你可以做的一些事情. 最简单的,增加InnoDB表空间大小的 ...

  3. nodejs 静态资源服务与接口代理跨域

    首先需要 npm install express 和 npm install request 代码如下: const express = require('express'); const path ...

  4. linux文件属性文文件类型知识

    文件类型分别介绍: 1.普通文件:我们通过用ls  -l来查看xxx.sql的属性,可以看到第一列内容为-rw-r--r--,值得注意的是第一个符号是-(英文字符减号),在Linux中,以这样的字符开 ...

  5. MySQL创建根据经纬度计算距离的函数

    按照经纬度计算距离 日常开发中,特别是做微信项目时,经常会遇到根据用户地理位置来展示附近商家的功能,通常解决这种问题的思路是,后台设置商家的经纬度,然后再根据前台传的经纬度进行计算,具体经纬度转换以及 ...

  6. 【android】android对位图文件的支持

    Android 支持以下三种格式的位图文件:.png(首选)..jpg(可接受)..gif(不建议).

  7. linux下GPIO的用户层操作(sysfs)

    linux的GPIO通过sysfs为用户提供服务,下面是linux kernel里的说明文档,学习一下. GPIO Sysfs Interface for Userspace ============ ...

  8. Cheese Aizu - 0558 (搜索题)

    Time limit8000 ms Memory limit131072 kB チーズ () 問題 今年も JOI 町のチーズ工場がチーズの生産を始め,ねずみが巣から顔を出した.JOI 町は東西南北に ...

  9. hdu 5459

    Problem Description I've sent Fang Fang around 201314 text messages in almost 5 years. Why can't she ...

  10. python字符串、列表和字典的说明

    python字符串.列表和字典的说明 字符串.列表.字典 字符串的作用存储一段数据信息.例如 info = '我爱北京天安门' ,在调取的时候可以直接调取,灵活方便,print(info) 就可以把刚 ...