Farmer John has N (1 <= N <= 25,000) rectangular barns on his farm, all with sides parallel to the X and Y axes and integer corner coordinates in the range 0..1,000,000. These barns do not overlap although they may share corners
and/or sides with other barns. 

Since he has extra cows to milk this year, FJ would like to expand some of his barns. A barn has room to expand if it does not share a corner or a wall with any other barn. That is, FJ can expand a barn if all four of its walls can be pushed outward by at least
some amount without bumping into another barn. If two barns meet at a corner, neither barn can expand. 

Please determine how many barns have room to expand.

Input

Line 1: A single integer, N 

Lines 2..N+1: Four space-separated integers A, B, C, and D, describing one barn. The lower-left corner of the barn is at (A,B) and the upper right corner is at (C,D).

Output

Line 1: A single integer that is the number of barns that can be expanded.

Sample Input

5
0 2 2 7
3 5 5 8
4 2 6 4
6 1 8 6
0 0 8 1

Sample Output

2

Hint

Explanation of the sample: 

There are 5 barns. The first barn has its lower-left corner at (0,2) and its upper-right corner at (2,7), and so on. 

Only two barns can be expanded --- the first two listed in the input. All other barns are each in contact with at least one other barn.

思路:

把四条边拆开 存到两个数组里

排序 y方向的先按照x排 再按照y方向上的起点排

x方向同理

遍历 对于每一个点 所有loc和他相同的 看看在不在重合范围内 并且更新范围

对于这个点本身的计数要特别一点 不然会重复

用cin cout会T 还是不长记性哦

可能真的痛经痛傻了 洗洗睡了洗洗睡了

#include <iostream>
#include <algorithm>
#include <cstring> #include <cstdio> #include <cmath> using namespace std;
#define PI 3.1415926
#define EPS 1.0e-6 struct Point {
Point(){}
Point(double x, double y, double z):x(x), y(y), z(z){}
double x,y, z; };
struct rect{
Point left_bottom;
Point right_up;
};
struct barn{
int index;
int st, ed, loc;
}hh[500005], ll[500005]; bool cmp(barn a, barn b)
{
if(a.loc == b.loc)
return a.st < b.st;
return a.loc < b.loc;
} int n, ans;
rect rec[25005];
bool vis[25005]; void solve(barn *bar, int n)
{
int i = 0;
while(i < n){
/*if(vis[bar[i].index]){
i++;
continue;
}*/
int pos = bar[i].loc;
int cnt = 0;
int first = i;
int ed = bar[i].ed;
i++;
while(i < n && bar[i].loc == pos && bar[i].st <= ed){
if(bar[i].ed > ed) ed = bar[i].ed;
if(!vis[bar[i].index]){
vis[bar[i].index] = true;
ans--;
}
cnt++;
i++;
}
if(cnt){
if(!vis[bar[first].index]){
vis[bar[first].index] = true;
ans--;
} }
}
} int main()
{
//while(cin>>n){
scanf("%d",&n);
ans = n;
//memset(vis, 0, sizeof(vis));
for(int i = 0; i < n; i++){
int left, bottom, right, up;
scanf("%d%d%d%d",&left, &bottom, &right, &up);
hh[2 * i].index = hh[2 * i + 1].index = i;
ll[2 * i].index = ll[2 * i + 1].index = i;
hh[2 * i].st = hh[2 * i + 1].st = bottom;
hh[2 * i].ed = hh[2 * i + 1].ed = up;
hh[2 * i].loc = left;hh[2 * i + 1].loc = right;
ll[2 * i].st = ll[2 * i + 1].st = left;
ll[2 * i].ed = ll[2 * i + 1].ed = right;
ll[2 * i].loc = bottom; ll[2 * i + 1].loc = up;
} sort(hh, hh + 2 * n, cmp);
sort(ll, ll + 2 * n, cmp);
solve(hh, 2 * n);
solve(ll, 2 * n);
//int ans = 0;
//for(int i = 0; i < n; i++){
// if(!vis[i])ans++;
//}
printf("%d\n", ans);
//}
return 0; }

poj3168 Barn Expansion【计算几何 平面扫描】的更多相关文章

  1. poj 3168 Barn Expansion

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

  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 (几何+排序)

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

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

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

  5. 基于正向扫描的并行区间连接平面扫描算法(IEEE论文)

    作者: Panagiotis Bouros ∗Department of Computer ScienceAarhus University, Denmarkpbour@cs.au.dkNikos M ...

  6. 计算几何 平面最近点对 nlogn分治算法 求平面中距离最近的两点

    平面最近点对,即平面中距离最近的两点 分治算法: int SOLVE(int left,int right)//求解点集中区间[left,right]中的最近点对 { double ans; //an ...

  7. poj_3168 平面扫描

    题目大意 给定平面上N个矩形的位置(给出矩形的左下角和右上角的坐标),这些矩形有些会有重叠,且重叠只会出现矩形的边重合全部或部分,矩形的顶点重合,而不会出现一个矩形的顶点位于另一个矩形的内部.     ...

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

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

  9. TTTTTTTTTTTTTTT poj 2932 Coneology 平面扫描+STL

    题目链接 题意:有n个圆,圆之间不存在相交关系,求有几个不被其他任何圆包含的圆,并输出圆的编号: #include <iostream> #include <cstdio> # ...

随机推荐

  1. JavaWeb跨域访问问题

    转载: http://blog.csdn.net/zjq_1314520/article/details/65449279 最后的解决方案如下: 在 tomcat 的 conf目录下找到 web.xm ...

  2. 一个非常好的C#字符串操作处理类StringHelper.cs

    /// <summary> /// 类说明:Assistant /// 编 码 人:苏飞 /// 联系方式:361983679 /// 更新网站:http://www.sufeinet.c ...

  3. Python中的and/or

    在Python中,可以通过and,or和not进行逻辑运算,下面就来看看and和or的简单介绍. 逻辑与-and 对于包含and运算的表达式,Python解释器将从左到右扫描,返回第一个为假的表达式值 ...

  4. 【代码审计】CLTPHP_v5.5.3前台XML外部实体注入漏洞分析

    0x01 环境准备 CLTPHP官网:http://www.cltphp.com 网站源码版本:CLTPHP内容管理系统5.5.3版本 程序源码下载:https://gitee.com/chichu/ ...

  5. PHP代码审计笔记--代码执行漏洞

    漏洞形成原因:客户端提交的参数,未经任何过滤,传入可以执行代码的函数,造成代码执行漏洞. 常见代码注射函数: 如:eval.preg_replace+/e.assert.call_user_func. ...

  6. Ajax 分析方法

    我们如何查看到 Ajax 请求: 以 https://m.weibo.cn/u/2830678474 这个网页为例,按 F12,加载网页,然后选择资源类型为 XHR 的就可以看到 Ajax 请求了 我 ...

  7. cannot access android.support.v4.app.BaseFragmentActivityJB的解决

    //implementation 'com.android.support:appcompat-v7:26.1.0' 改成implementation 'com.android.support:app ...

  8. linux下使用ftp传递文件的shell脚本

    使用ftp传递文件,传递过程中防止对方取文件,后缀名为writing,传完后再改回来. #!/bin/bash dstpath=cnet ftpip="127.0.0.1" log ...

  9. iOS - UICollectionView 瀑布流 添加表头视图的坑

    UICollectionView 瀑布流 添加表头视图的坑 首先是,需求加了个头视图在顶部,在collectionView中的头视图跟TableView的不一样,TableView的表头只要设置tab ...

  10. hive报错: Specified key was too long; max key length is 767 bytes

    废话不多说,报错如下: DataNucleus.Datastore (Log4JLogger.java:error(115)) - An exception was thrown while addi ...