题目描述

After several harsh winters, Farmer John has decided it is time to re-paint his farm. The farm consists of N fenced enclosures (1 <= N <= 50,000), each of which can be described by a rectangle in the 2D plane whose sides are parallel to the x and y axes. Enclosures may be contained within other enclosures, but no two fences intersect, so if two enclosures cover the same area of the 2D plane, one must be contained within the other.

FJ figures that an enclosure contained within another enclosure will not be visible to the outside world, so he only wants to re-paint enclosures that are themselves not contained within any other enclosures. Please help FJ determine the total number of enclosures he needs to paint.

经过几个严冬,农场主约翰决定是重新粉刷农场的时候了。该农场由nn个围栏围成(1<=n=500001<=n=50000),每一个都可以用二维平面上的矩形来描述,其两侧平行于x和y轴。牛圈可能包含在其他牛圈中,但没有两个栅栏相交(不同牛圈的边不会有接触)。因此如果两个牛圈覆盖了二维平面的同一区域,那么一个必须包含在另一个内。

FJ知道,被其他牛圈包含的牛圈是不会被外面的人看到的。众所周知,FJ非常懒,所以他只想刷露在外面的牛圈,请帮助他求出总共需要刷的牛圈的个数。

输入输出格式

输入格式:

  • Line 1: The number of enclosures, N.

  • Lines 2..1+N: Each line describes an enclosure by 4 space-separated integers x1, y1, x2, and y2, where (x1,y1) is the lower-left corner of the enclosure and (x2,y2) is the upper-right corner. All coordinates are in the range 0..1,000,000.

第一行 一个数,牛圈的总数nn

第二到n+1n+1行 每行四个数,起点坐标x1,y1x1,y1和终点坐标x2,y2x2,y2

输出格式:

  • Line 1: The number of enclosures that are not contained within other enclosures.

FJ总共需要刷的牛圈的个数

输入输出样例

输入样例#1: 复制

3
2 0 8 9
10 2 11 3
4 2 6 5
输出样例#1: 复制

2

说明

There are three enclosures. The first has corners (2,0) and (8,9), and so on.

Enclosure 3 is contained within enclosure 1, so there are two enclosures not contained within other enclosures.

思路:围栏i包含围栏j的必要条件:x1[j]>x2[i]

  也就是这样的:

然后还应该满足一下几个条件:

  x1[i]<x1[j];

  y1[i]<y1[j];

  x2[i]>x2[j];

  y2[i]>y2[j];

 所以就可以写出cpp了:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,L,R,ans;
struct nond{
int x1,y1,x2,y2;
}v[];
int cmp(nond a,nond b){
return a.x1<b.x1;
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
v[i].x1=a;v[i].y1=b;v[i].x2=c;v[i].y2=d;
}
sort(v+,v++n,cmp);ans=n;
for(L=,R=;R<=n;R++){
while(v[L].x2<=v[R].x1) L++;
for(int i=L;i<=R;i++)
if(v[R].x1>v[i].x1&&v[R].y2<v[i].y2&&v[i].y1<v[R].y1&&v[i].x2>v[R].x2){
ans--;break;
}
}
cout<<ans;
}

洛谷 P3079 [USACO13MAR]农场的画Farm Painting的更多相关文章

  1. 洛谷P2905 [USACO08OPEN]农场危机Crisis on the Farm

    P2905 [USACO08OPEN]农场危机Crisis on the Farm 题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每 ...

  2. 洛谷 P2905 [USACO08OPEN]农场危机Crisis on the Farm

    题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每一堆里,30只奶牛一只踩在另一只的背上,叠成一座牛塔.牧场 里还有M(1 < ...

  3. 洛谷 P2921 在农场万圣节Trick or Treat on the Farm题解

    题意翻译 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定 ...

  4. 洛谷P3080 [USACO13MAR]牛跑The Cow Run

    P3080 [USACO13MAR]牛跑The Cow Run 题目描述 Farmer John has forgotten to repair a hole in the fence on his ...

  5. 洛谷 P3078 [USACO13MAR]扑克牌型Poker Hands

    P3078 [USACO13MAR]扑克牌型Poker Hands 题目描述 Bessie and her friends are playing a unique version of poker ...

  6. 洛谷P3078 [USACO13MAR]扑克牌型Poker Hands

    题目描述 Bessie and her friends are playing a unique version of poker involving a deck with \(N\) (\(1 \ ...

  7. 洛谷 P2921 在农场万圣节

    https://www.luogu.org/problemnew/show/P2921 开始感觉这题30行代码就可以搞定,还是太菜啦,还是乖乖地写了tarjan. 对图进行缩点,那么这个强联通分量中的 ...

  8. 洛谷五月月赛【LGR-047】划水记

    虽然月赛有些爆炸,但我永远资瓷洛谷! 因为去接水,所以迟到了十几分钟,然后洛谷首页就打不开了-- 通过洛谷题库间接打开了比赛,看了看\(TA\),WTF?博弈论?再仔细读了读题,嗯,判断奇偶性,不过要 ...

  9. 缩点【洛谷P2921】 [USACO08DEC]在农场万圣节Trick or Treat on the Farm

    [洛谷P2921] [USACO08DEC]在农场万圣节Trick or Treat on the Farm 题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N< ...

随机推荐

  1. pl/sql sql窗口允许输出和允许变量替换

    pl/sql sql窗口允许输出和允许变量替换 允许输出:类似在命令窗口中输入的 setserveroutput on; 允许变量替换:如果点击了这个,类似于执行 set define off命令 在 ...

  2. iOS_21团购_地图功能

    终于效果图: 右下角的回到用户位置button: MapController控制器, 是主控制器左側dock上面的[地图]button相应的控制器, 继承自ShowDealDetailControll ...

  3. Apache Pig的前世今生

    近期,散仙用了几周的Pig来处理分析我们站点搜索的日志数据,感觉用起来非常不错,今天就写篇笔记介绍下Pig的由来,除了搞大数据的人,可能非常少有人知道Pig是干啥的.包含一些是搞编程的,但不是搞大数据 ...

  4. Leetcode--easy系列2

    #14 Longest Common Prefix Write a function to find the longest common prefix string amongst an array ...

  5. Android App 内存泄露之Thread

    Thread 内存泄露 线程也是造成内存泄露的一个重要的源头.线程产生内存泄露的主要原因在于线程生命周期的不可控. 1.看一下以下是否存在问题 <span style="white-s ...

  6. [学习笔记—Objective-C]《Objective-C-基础教程 第2版》第十一章 属性

    11.1 使用属性值 @property float rainHandling; //表明此类具有float类型的属性,其名称为rainHandling 注意:属性的名称不必与实例变量名称同样. @s ...

  7. hdu5592/BestCoder Round #65 树状数组寻找第K大

    ZYB's Premutation    Memory Limit: 131072/131072 K (Java/Others) 问题描述 ZYBZYB有一个排列PP,但他只记得PP中每个前缀区间的逆 ...

  8. 英语发音规则---F字母

    英语发音规则---F字母 一.总结 一句话总结: 1.F/FF发[f]音? fly [flaɪ] vi. 飞 fine [faɪn] adj. 好的 float [fləʊt] vt. 使漂浮 fra ...

  9. zzulioj--1637--Happy Thanksgiving Day - WoW yjj!(水)

    1637: Happy Thanksgiving Day - WoW yjj! Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 104  Solved: ...

  10. (转)IOS http请求的get 和 post的请求的区别

    从表面的意思看get 和 post的区别get就是获取数据,post就是发送数据.这个是误区.其实两者都可以的,在IOS向服务器发送请求里面可以带参数. 那么这些误区是怎么出现的呢?先看看一下对htt ...