【题目链接】 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 (几何基础)的更多相关文章

  1. POJ 3168 Barn Expansion (几何+排序)

    题目链接:id=3168">POJ 3168 Barn Expansion 题意:抽象出来就是给出n个矩形的坐标是(左下角和右上角的坐标,矩形的边都是平行x,y轴),问有几个矩形和其它 ...

  2. poj 3168 Barn Expansion 几何yy

    题链:http://poj.org/problem? id=3168 Barn Expansion Time Limit: 1000MS   Memory Limit: 65536K Total Su ...

  3. poj 3168 Barn Expansion

    Barn Expansion Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2465   Accepted: 666 Des ...

  4. poj3168 Barn Expansion【计算几何 平面扫描】

    Farmer John has N (1 <= N <= 25,000) rectangular barns on his farm, all with sides parallel to ...

  5. POJ 2318 - TOYS - [计算几何基础题]

    题目链接:http://poj.org/problem?id=2318 Time Limit: 2000MS Memory Limit: 65536K Description Calculate th ...

  6. poj 1039 Pipe(几何基础)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9932   Accepted: 3045 Description ...

  7. 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 ...

  8. POJ 3168 排序+扫描

    题意: 思路: 我们可以把每个矩形拆成四条线 与x轴平行的放在一起 与y轴平行的放在一起 排个序 判一判有没有交 有交 则说明不可扩张 统计一下 就可以了 处理的姿势很重要 姿势不对毁一生 //By ...

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. dhcp 和ntpdate时间同步

    为了防止路由器的dhcp服务干扰实验,我们2台机器分别新加了1快网卡. vmnet4 dhcp安装 [root@ygy130 ~]# yum -y install dhcp 将配置文件放在/etc/d ...

  2. Codeforces Round #526 (Div. 2) A.B

    A. The Fair Nut and Elevator 题目链接:https://codeforces.com/contest/1084/problem/A 题意: 一栋房子有n层楼,同时有个电梯( ...

  3. 编写clearedit的安卓控件

    1.写一个自定义的控件 public class ClearEditText extends AppCompatEditText implements View.OnFocusChangeListen ...

  4. ppk和pem证书互转

    首先你得去下载个putty pem:通用证书格式 ppk:为putty下面的专有格式     pem->ppk 直接通过putty下的puttygen.exe 选的Load private ke ...

  5. salt-api的使用

    curl -k https://192.168.74.129:8006/ -H "Accept: application/x-yaml" -H "X-Auth-Token ...

  6. codeforces B. Okabe and Banana Trees 结论题

    题目传送门 这道题 枚举一波y就好了 要求x,y整数 所以y最多1000个 然后算一波答案更新就好了 233 #include<cstdio> #include<cstring> ...

  7. bzoj 1076 状压DP

    我们设w[i][s]为当前到第i关,手中的物品为s的时候,期望得分为多少,其中s为二进制表示每种物品是否存在. 那么就比较容易转移了w[i][s]=(w[i-1][s']+v[j]) *(1/k),其 ...

  8. bzoj1053 搜索

    2013-11-16 17:43 原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1053 因为使pi(prime[i])<20亿的i不 ...

  9. [vue-router] Failed to resolve async component default: Error: Loading chunk 0 failed.

    在整合laravel5.4 和vue2.1的时候遇到一个奇怪的问题 Uncaught SyntaxError: Unexpected token < Error: Loading chunk 0 ...

  10. 设置session过期时间

    1如下是登录注册和记住密码的功能: # -*- coding: utf-8 -*- def cms_login(request): if request.method == 'GET': return ...