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 ...
随机推荐
- 注意@Bean中的initMethod和destroyMethod
@Configuration public class AppConfig { @Bean(initMethod = "init") public Foo foo() { retu ...
- ZooKeeper Watcher注意事项
zookeeper watch的定义如下:watch事件是一次性触发器,当watch监视的数据发生变化时,通知设置了该watch的client,即watcher. 需要注意三点: 1.一次性触发器 c ...
- 获取html元素内容
html: <!DOCTYPE ><html> <head> <meta http-equiv="Content-Type" conten ...
- mybatis 关系映射
一:订单商品数据模型 1.数据库执行脚本 创建数据库表代码: 1 CREATE TABLE items ( 2 id INT NOT NULL AUTO_INCREMENT, 3 itemsname ...
- loj6029 「雅礼集训 2017 Day1」市场
传送门:https://loj.ac/problem/6029 [题解] 考虑如果有一些近似连续的段 比如 2 2 2 3 3 3,考虑在除3意义下,变成0 0 0 1 1 1,相当于整体-2 又:区 ...
- 51nod 扔盘子
题目传送门 这道题一开始写了n方的算法 果不其然 它T了 所以就想想o(n)的算法 写不出来 就像sbzhq学习了一下 这道题啊 要维护一下从深度1到n每一段的最小值以及他的位置 然后就暴力搞一搞就o ...
- 【洛谷 P4211】[LNOI2014]LCA(树链剖分,差分)
题目链接 看到题目肯定首先想到要求LCA(其实是我菜),可乍一看,n与q的规模为5W, 求LCA的复杂度为\(O(logN)\),那么总时间复杂度为\(O(nq\ log\ n)\). 怎么搞呢? 会 ...
- Invalidate()(转)
原文转自 http://m.blog.csdn.net/blog/piaopiaopiaopiaopiao/41521211 使用Invalidate(TRUE)函数时,它会向消息队列中添加了WM_E ...
- GitLab版本管理【转】
转自:http://www.cnblogs.com/wintersun/p/3930900.html GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目 ...
- 安全测试===Mysql 注入技巧学习 MySQL注入技巧(1)
默认存在的数据库: mysql 需要root权限读取 information_schema 在5以上的版本中存在 测试是否存在注入方法 假:表示查询是错误的 (MySQL 报错/返回页面与原来不同) ...