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 ...
随机推荐
- c++编辑器下载地址
https://msdn.itellyou.cn/ 输入上述地址选中下图所示的按钮:
- 7月24号day16总结
一开始显示出现问题,js路径不能应用,因为用的是springMVC框架书写,所以有路径的保护和静态引用地址时需要注意的地方 今天进行了最后项目的优化,包括map清洗数据部分的代码和echarts显示的 ...
- IOS 学习资料整理{非常有用,强烈推荐}
绝地地的资源博客:我是雷锋不用谢~~啦啦啦 https://blog.csdn.net/kunga0814/article/details/82117090
- java字符串 64位编码
byte[] encodeBase64 = Base64.encodeBase64("到了是是是是".getBytes("UTF-8")); System.ou ...
- Ubuntu pppoe 拨号上网
-------------蓝色是终端里面的连接方式,可以不看--------------------- ADSL上网,Ubuntu下是可以的,虽然以前没用过拨号上网,不过查了查也不是很麻烦. 打开终端 ...
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported解决!
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported解决 ...
- RPC-Thrift(三)
TProtocol TProtocol定义了消息怎么进行序列化和反序列化的. TProtocol的类结构图如下: TBinaryProtocol:二进制编码格式: TCompactProtocol:高 ...
- 【poj3415-Common Substrings】sam子串计数
题意: 给出两个串,问这两个串的所有的子串中(重复出现的,只要是位置不同就算两个子串),长度大于等于k的公共子串有多少个. 题解: 这题好像大神们都用后缀数组做..然而我在sam的题表上看到这题,做 ...
- AtCoder Regular Contest 082 F
Problem Statement We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contai ...
- CentOS erlang安装
1. http://www.erlang.org/下载erlang,解压缩,进入目录,检查环境 alex$ cd otp_src_18. alex$ ./configure ************* ...