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. ... 
随机推荐
- javascript 完整知识点整理
			by 蔡舒啸 目录 一 5种基本类型 typeof 关键字 三种强制类型转换 日期 二 if语句for语句whiledo-whileswitch-case 比较运算符 逻辑运算符 if for语句 w ... 
- MySQL Innodb表空间不足的处理方法
			官方给出的解决方案: 添加和删除 InnoDB 数据和日志文件 这一节描述在InnoDB表空间耗尽空间之时,或者你想要改变日志文件大小之时,你可以做的一些事情. 最简单的,增加InnoDB表空间大小的 ... 
- nodejs 静态资源服务与接口代理跨域
			首先需要 npm install express 和 npm install request 代码如下: const express = require('express'); const path ... 
- linux文件属性文文件类型知识
			文件类型分别介绍: 1.普通文件:我们通过用ls -l来查看xxx.sql的属性,可以看到第一列内容为-rw-r--r--,值得注意的是第一个符号是-(英文字符减号),在Linux中,以这样的字符开 ... 
- MySQL创建根据经纬度计算距离的函数
			按照经纬度计算距离 日常开发中,特别是做微信项目时,经常会遇到根据用户地理位置来展示附近商家的功能,通常解决这种问题的思路是,后台设置商家的经纬度,然后再根据前台传的经纬度进行计算,具体经纬度转换以及 ... 
- 【android】android对位图文件的支持
			Android 支持以下三种格式的位图文件:.png(首选)..jpg(可接受)..gif(不建议). 
- linux下GPIO的用户层操作(sysfs)
			linux的GPIO通过sysfs为用户提供服务,下面是linux kernel里的说明文档,学习一下. GPIO Sysfs Interface for Userspace ============ ... 
- Cheese Aizu - 0558     (搜索题)
			Time limit8000 ms Memory limit131072 kB チーズ () 問題 今年も JOI 町のチーズ工場がチーズの生産を始め,ねずみが巣から顔を出した.JOI 町は東西南北に ... 
- hdu   5459
			Problem Description I've sent Fang Fang around 201314 text messages in almost 5 years. Why can't she ... 
- python字符串、列表和字典的说明
			python字符串.列表和字典的说明 字符串.列表.字典 字符串的作用存储一段数据信息.例如 info = '我爱北京天安门' ,在调取的时候可以直接调取,灵活方便,print(info) 就可以把刚 ... 
