poj 3168 Barn Expansion
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2465 | Accepted: 666 |
Description
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
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
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
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.
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的更多相关文章
- POJ 3168 Barn Expansion (几何+排序)
题目链接:id=3168">POJ 3168 Barn Expansion 题意:抽象出来就是给出n个矩形的坐标是(左下角和右上角的坐标,矩形的边都是平行x,y轴),问有几个矩形和其它 ...
- poj 3168 Barn Expansion 几何yy
题链:http://poj.org/problem? id=3168 Barn Expansion Time Limit: 1000MS Memory Limit: 65536K Total Su ...
- POJ 3168 Barn Expansion (几何基础)
[题目链接] http://poj.org/problem?id=3168 [题目大意] 给出一些矩形,没有相交和包含的情况,只有相切的情况 问有多少个矩形没有相切或者边角重叠 [题解] 我们将所有的 ...
- poj3168 Barn Expansion【计算几何 平面扫描】
Farmer John has N (1 <= N <= 25,000) rectangular barns on his farm, all with sides parallel to ...
- POJ 3168 排序+扫描
题意: 思路: 我们可以把每个矩形拆成四条线 与x轴平行的放在一起 与y轴平行的放在一起 排个序 判一判有没有交 有交 则说明不可扩张 统计一下 就可以了 处理的姿势很重要 姿势不对毁一生 //By ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
随机推荐
- ios 设计模式总结
设计模式:备注:消息传递模型(Message Passing)是Objective-C语言的核心机制.在Objective-C中,没有方法调用这种说法,只有消息传递.在C++或Java中调用某个类的方 ...
- VS2013连接SQL Server 2008 R2测试
第一步,打开SQL Server 08,这里要说明一下,一定要开启服务,很多时候我们重启电脑以后,SQL Server的保留进程会被类似电脑管家之类的保护程序关闭,于是乎连接了半天的数据库都连不上. ...
- 配置淘宝镜像,不使用怪异的cnpm
npm config set registry https://registry.npm.taobao.org --global npm config set disturl https://npm. ...
- c++ 指针数组,输入4个季度的花费,计算出总花费
#include <iostream> #include <array> #include <string> const int Seasons = 4; cons ...
- NOIP模拟赛 抓牛
[题目描述] 农夫约翰被通知,他的一只奶牛逃逸了!所以他决定,马上出发,尽快把那只奶牛抓回来. 他们都站在数轴上.约翰在N(O≤N≤100000)处,奶牛在K(O≤K≤100000)处.约翰有两种办法 ...
- HashMap与ArrayMap(和SparseArray)的比较与选择
HashMap与ArrayMap(和SparseArray)的比较与选择 2017年12月26日 06:04:38 阅读数:61 标签: androidjavahashmaparraymap数据结构 ...
- linux文件属性之linux文件删除原理
Linux是通过link的数量来控制文件删除的,只有当一个文件不存在任何link的时候,这个文件才会被删除.一般来说,每个文件都有2个link计数器:i_count和i_nlink. i_count的 ...
- 17.Yii2.0框架模型添加记录
目录 新建控制器 HomeController.php 新建model Article.php 新建控制器 HomeController.php D:\xampp\htdocs\yii\control ...
- 让Python带你看一场唯美的横飘雪!
“北国风光,千里冰封,万里雪飘”,这句诗描写了一句美丽肃静的风光图,恰逢昨天笔者这边也下了一场比较大的雪,要不今天就用Python带大家也来领略一次美丽的雪景? 开发环境 版本:Python3.6 系 ...
- python-matplotlib-lec0
直奔主题吧..以下是对matplotlib画图的简单讲解,代码已测试. win7 + pycharm + python 2.7 参考文档: http://old.sebug.net/paper/boo ...