题意:

思路:

我们可以把每个矩形拆成四条线

与x轴平行的放在一起

与y轴平行的放在一起

排个序 判一判有没有交 有交 则说明不可扩张 统计一下 就可以了

处理的姿势很重要

姿势不对毁一生

//By SiriusRen
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 55555
int n,x1,y1,x2,y2,cnt,vis[N],ans,maxx;
struct Edgex{int x,y1,y2,id;bool operator < (const Edgex &a)const{if(x!=a.x)return x<a.x;return y2<a.y2;}}edgex[N];
struct Edgey{int y,x1,x2,id;bool operator < (const Edgey &a)const{if(y!=a.y)return y<a.y;return x1<a.x1;}}edgey[N];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d%d%d",&x1,&y1,&x2,&y2),vis[i]=1,
edgex[++cnt].x=x1,edgex[cnt].y1=y2,edgex[cnt].y2=y1,edgex[cnt].id=i,
edgey[cnt].y=y1,edgey[cnt].x1=x1,edgey[cnt].x2=x2,edgey[cnt].id=i,
edgex[++cnt].x=x2,edgex[cnt].y1=y2,edgex[cnt].y2=y1,edgex[cnt].id=i,
edgey[cnt].y=y2,edgey[cnt].x1=x1,edgey[cnt].x2=x2,edgey[cnt].id=i;
sort(edgex+1,edgex+1+cnt),sort(edgey+1,edgey+1+cnt);
for(int i=1,j=i;i<=cnt;i=j,maxx=edgex[i].y1){
while(edgex[i].x==edgex[j].x)j++;
for(int k=i+1;k<j;k++){
if(edgex[k].y2<=maxx)vis[edgex[k].id]=vis[edgex[k-1].id]=0;
maxx=max(maxx,edgex[k].y1);
}
}
for(int i=1,j=i;i<=cnt;i=j,maxx=edgey[i].x2){
while(edgey[i].y==edgey[j].y)j++;
for(int k=i+1;k<j;k++){
if(edgey[k].x1<=maxx)vis[edgey[k].id]=vis[edgey[k-1].id]=0;
maxx=max(maxx,edgey[k].x2);
}
}
for(int i=1;i<=n;i++)ans+=vis[i];
printf("%d\n",ans);
}

POJ 3168 排序+扫描的更多相关文章

  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题目排序的Java程序

    POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...

  4. POJ 2388(排序)

    http://poj.org/problem?id=2388 题意:就N个数的中位数. 思路:用快排就行了.但我没用快排,我自己写了一个堆来做这个题.主要还是因为堆不怎么会,这个拿来练练手. #inc ...

  5. POJ 1833 排序

    http://poj.org/problem?id=1833 题意: 给出一个排序,求出它之后的第k个排序. 思路: 排序原理: 1.如果全部为逆序时,说明已经全部排完了,此时回到1~n的排序. 2. ...

  6. POJ 3168 Barn Expansion (几何基础)

    [题目链接] http://poj.org/problem?id=3168 [题目大意] 给出一些矩形,没有相交和包含的情况,只有相切的情况 问有多少个矩形没有相切或者边角重叠 [题解] 我们将所有的 ...

  7. POJ 2932 平面扫描 /// 判断圆的包含关系

    题目大意: 平面上有n个两两不相交的圆,给定圆的圆心(x,y)和半径 r 求所有最外层的 即 不包含于其他圆内部的圆 挑战258页 平面扫描 记录所有圆的左端和右端 排序后 逐一扫描 将到当前圆为止的 ...

  8. codeforces 1284E. New Year and Castle Construction(极角排序+扫描枚举)

    链接:https://codeforces.com/problemset/problem/1284/E 题意:平面上有n个点,问你存在多少组四个点围成的四边形 严格包围某个点P的情况.不存在三点共线. ...

  9. poj 3168 Barn Expansion

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

随机推荐

  1. 二维码扫描ZXing简化

    最近项目中有需要用到二维码扫描功能,于是查了相关资料,也没有过多地研究ZXing源码,只是有了最简单的功能,因为下载大牛的demo已经完全实现了功能,只是对其中的扫描线做了更改,需要的朋友可以直接使用 ...

  2. windows如何批量添加路由表

    我大约有2000条路由,需要批量导入,如何才能快速导入,快速删除呢.如果直接用命令添加路由表的话感觉很慢. windows如何批量添加路由表 >> csharp这个答案描述的挺清楚的:ht ...

  3. PostgreSQL Replication之第九章 与pgpool一起工作(4)

    9.4 设置复制和负载均衡 要配置pgpool,我们可以简单地使用一个包含一种典型的配置信息的已经存在的样本文件,将它拷贝到我们的配置目录并修改之: $ cp /usr/local/etc/pgpoo ...

  4. Chromium Graphics: Compositor Thread Architecture

    Compositor Thread Architecture <jamesr, enne, vangelis, nduca> @chromium.org Goals The main re ...

  5. SQL替换制表、回车、换行符和首尾空格

    SQL替换制表.回车.换行符和首尾空格 最近在批量修复数据的时候,需要利用excel导入大量数据.客户提供的数据是没有规范的,大部分数据行都有制表符.回车符.换货符,以及我需要将数据进行首位去重. 目 ...

  6. 通俗易懂的Git使用入门教程

    原文链接:点我 首先新司机接触 Git 和 Github 可能会搞不清楚两者之间的关系,这里稍微解释一下: 1.Git是一款免费.开源的分布式版本控制系统 2.Github是用Git做版本控制的代码托 ...

  7. java源码学习

    Collection List ArrayList LinkedList Vector Stack Set HashSet TreeSet Map HashMap TreeMap LinkedHash ...

  8. CF546E Soldier and Traveling(网络流,最大流)

    CF546E Soldier and Traveling 题目描述 In the country there are \(n\) cities and \(m\) bidirectional road ...

  9. Flexible implementation of a system management mode (SMM) in a processor

    A system management mode (SMM) of operating a processor includes only a basic set of hardwired hooks ...

  10. 水池接雨水的经典问题I&II

    https://leetcode.com/problems/trapping-rain-water https://leetcode.com/problems/trapping-rain-water- ...