POJ 3168 Barn Expansion (几何基础)
【题目链接】 http://poj.org/problem?id=3168
【题目大意】
给出一些矩形,没有相交和包含的情况,只有相切的情况
问有多少个矩形没有相切或者边角重叠
【题解】
我们将所有的与x轴平行的线段和与y周平行的线段分开处理,判断是否出现重合
对重合的两个矩形进行标识,最后没有被标识过的矩形数目就是答案。
【代码】
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=30010;
struct data{
int id,d,x,y;
data(){};
data(int _d,int _x,int _y,int _id):d(_d),x(_x),y(_y),id(_id){}
};
vector<data> sx,sy;
bool vis[N];
bool cmp(data a,data b){
if(a.d!=b.d)return a.d<b.d;
if(a.x!=b.x)return a.x<b.x;
return a.y<b.y;
}
int n,a,b,c,d;
void solve(){
sx.clear();sy.clear();
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++){
scanf("%d%d%d%d",&a,&b,&c,&d);
sy.push_back(data(b,a,c,i));
sy.push_back(data(d,a,c,i));
sx.push_back(data(a,b,d,i));
sx.push_back(data(c,b,d,i));
}sort(sx.begin(),sx.end(),cmp);
sort(sy.begin(),sy.end(),cmp);
int t=sy[0].y;
for(int i=1;i<sy.size();i++){
if(sy[i-1].d==sy[i].d){
if(t>=sy[i].x){
vis[sy[i].id]=vis[sy[i-1].id]=1;
}
}else t=sy[i].y;
t=max(sy[i].y,t);
}t=sx[0].y;
for(int i=1;i<sx.size();i++){
if(sx[i-1].d==sx[i].d){
if(t>=sx[i].x){
vis[sx[i].id]=vis[sx[i-1].id]=1;
}
}else t=sx[i].y;
t=max(sx[i].y,t);
}int ans=0;
for(int i=0;i<n;i++)if(!vis[i])ans++;
printf("%d\n",ans);
}
int main(){
while(~scanf("%d",&n))solve();
return 0;
}
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
Barn Expansion Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2465 Accepted: 666 Des ...
- poj3168 Barn Expansion【计算几何 平面扫描】
Farmer John has N (1 <= N <= 25,000) rectangular barns on his farm, all with sides parallel to ...
- POJ 2318 - TOYS - [计算几何基础题]
题目链接:http://poj.org/problem?id=2318 Time Limit: 2000MS Memory Limit: 65536K Description Calculate th ...
- poj 1039 Pipe(几何基础)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9932 Accepted: 3045 Description ...
- B - Toy Storage(POJ - 2398) 计算几何基础题,比TOYS多了个线段排序
Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing ...
- POJ 3168 排序+扫描
题意: 思路: 我们可以把每个矩形拆成四条线 与x轴平行的放在一起 与y轴平行的放在一起 排个序 判一判有没有交 有交 则说明不可扩张 统计一下 就可以了 处理的姿势很重要 姿势不对毁一生 //By ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- [Python]简单的外星人入侵游戏
alien_invasion.py: import sys import pygame from setting import Settings from ship import Ship impor ...
- JavaScript中Array(数组)的属性和方法(转)
数组有四种定义的方式 使用构造函数:var a = new Array();var b = new Array(8);var c = new Array("first", &quo ...
- Struts2 内建的验证规则
Struts2 内建的验证规则 conversion validator:转换验证器 date validator:日期验证器 double validator:浮点验证器 email validat ...
- 随机洗牌算法Knuth Shuffle和错排公式
Knuth随机洗牌算法:譬如现在有54张牌,如何洗牌才能保证随机性.可以这么考虑,从最末尾一张牌开始洗,对于每一张牌,编号在该牌前面的牌中任意一张选一张和当前牌进行交换,直至洗到第一张牌为止.参考代码 ...
- 【BZOJ】1692: [Usaco2007 Dec]队列变换
[算法]字符串hash [题解] 显然如果字母互不相同,贪心取是正确的. 如果存在字母相同,那么就换成比较后缀和前缀嘛. 但是要注意,不是后缀和前缀相同就能直接跳跃,每次必须只推一位. 取模的哈希比自 ...
- 【洛谷 SP283】NAPTIME - Naptime(DP)
题目链接 先考虑如果只有一天,那么该怎么做. 设\(f[i][j][1]\)表示前\(i\)个小时睡了\(j\)个小时并且第\(j\)个小时正在睡觉时的最大体力,\(f[i][j][1]\)表示前\( ...
- bzoj 1005 组合数学 Purfer Sequence
这题需要了解一种数列: Purfer Sequence 我们知道,一棵树可以用括号序列来表示,但是,一棵顶点标号(1~n)的树,还可以用一个叫做 Purfer Sequence 的数列表示 一个含有 ...
- mongodb安全
1.流程: (1)创建超级管理员 (2)修改配置文件,验证身份登录 (3)重启服务 (4)使用超级管理员登录 (5)创建普通用户 (6)使用普通用户登录对应的数据库 mongodb数据库角色: 1创建 ...
- POJ1458(最长公共子序列)
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44223 Accepted: 18 ...
- 最新Python异步编程详解
我们都知道对于I/O相关的程序来说,异步编程可以大幅度的提高系统的吞吐量,因为在某个I/O操作的读写过程中,系统可以先去处理其它的操作(通常是其它的I/O操作),那么Python中是如何实现异步编程的 ...