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 ;
}
最新文章
- hexo环境变量的配置问题
- 新冲刺Sprint3(第六天)
- python egg文件解压
- 第八十八天请假 PHP smarty模板 变量调节器,方法和块函数基本书写格式
- sparkStreaming与Kafka整合
- 设计模式(九)外观模式Facade(结构型)
- Revit 2015 API 的全部变化和新功能
- 【ORACLE】“System.Exception: System.Data.OracleClient 需要 Oracle 客户端软件 version 8.1.7 或更高版本。”解决办法
- [vijos 1642]班长的任务 [树形dp]
- 201521123028 《Java程序设计》 第9周学习总结
- 【转载】MySQL5.6.27 Release Note解读(innodb及复制模块)
- html网页引用中文字体,解决加载缓慢办法
- centos开启防火墙
- Linux下好用的屏幕录像软件kazam及截图软件shutter
- Unity3D学习笔记(二十六):MVC框架下的背包系统(1)
- django面试八
- spark核心原理
- 迷你MVVM框架 avalonjs1.5.2 发布
- PAT 1063 计算谱半径
- weblogic 12C集群环境下的session复制