2191: 【USACO】Crowded Cows
2191: 【USACO】Crowded Cows
时间限制: 1.000 Sec 内存限制: 64 MB
提交: 26 解决: 19
[命题人:][下载数据: 90]
提交状态报告
题目描述
Farmer John's N cows (1 <= N <= 50,000) are grazing along a one-dimensional fence. Cow i is standing at location x(i) and has height h(i) (1 <= x(i),h(i) <= 1,000,000,000). A cow feels "crowded" if there is another cow at least twice her height within distance D on her left, and also another cow at least twice her height within distance D on her right (1 <= D <= 1,000,000,000). Since crowded cows produce less milk, Farmer John would like to count the number of such cows. Please help him.
输入
* Line 1: Two integers, N and D. * Lines 2..1+N: Line i+1 contains the integers x(i) and h(i). The locations of all N cows are distinct.
输出
* Line 1: The number of crowded cows.
样例
输入 复制
6 4 10 3 6 2 5 3 9 7 3 6 11 2
输出 复制
2
提示
INPUT DETAILS: There are 6 cows, with a distance threshold of 4 for feeling crowded. Cow #1 lives at position x=10 and has height h=3, and so on. OUTPUT DETAILS: The cows at positions x=5 and x=6 are both crowded.
来源/分类
USACO 2013 November Silver
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;struct Cow {long long x , hi;bool operator < (const Cow &a) const {return hi > a.hi;}
};
Cow tag[50005];
long long n;
long long d , ans = 0;long long myabs(long long x) {return x>0?x:(-x);
}int main() {scanf("%d%lld",&n,&d);for(long long i=1; i<=n; i++)scanf("%lld%lld",&tag[i].x,&tag[i].hi);sort(tag+1 , tag+n+1);for(long long i=1; i<=n; i++) {long long flag1 = 0 , flag2 = 0;for(long long j=1; j<i; j++) {if(tag[j].hi < tag[i].hi*2)break;if(myabs(tag[j].x-tag[i].x) <= d) {if(tag[j].x > tag[i].x)flag1 = 1;if(tag[j].x < tag[i].x)flag2 = 1;if(flag1 && flag2) {ans++;break;}}} }printf("%lld",ans);return 0;
}
2191: 【USACO】Crowded Cows相关推荐
- jzoj 1594: 【USACO】The Chivalrous Cow(骑士牛)( 待加入)
1594: [USACO] 题目描述 Farmer John traded one of his cows for a cow that Farmer Don called 'The Knight' ...
- 2190: 【USACO】Farmer John has no Large Brown Cow
2190: [USACO]Farmer John has no Large Brown Cow 时间限制: 1.000 Sec 内存限制: 64 MB 提交: 16 解决: 12 [命题人:][下 ...
- 【USACO】双数? 单数?
[USACO]双数? 单数? 题意分析: 这道题的题意还是比较明了的,就是读入一个很大的数,判断它是奇数还是偶数. 解题思路: 因为我们知道,任意一个数最后一位是奇数,这个数就是奇数,偶数,同理. 这 ...
- 1584: 【USACO】双数? 单数?
1584: [USACO]双数? 单数? 时间限制: 1.000 Sec 内存限制: 64 MB 提交: 6305 解决: 2829 [命题人:][下载数据: 70] 提交状态报告 题目描述 B ...
- 【USACO】iCow播放器
[USACO]iCow播放器 题目: 被无止境的农活压榨得筋疲力尽后,Farmer John打算用他在MP3播放器市场新买的iCow来听些音乐,放松一下.FJ的iCow里存了N(1 <= N & ...
- 【USACO】贝茜的晨练计划
[USACO]贝茜的晨练计划 题目: 奶牛们打算通过锻炼来培养自己的运动细胞,作为其中的一员,贝茜选择的运动方式是每天进行N(1 <= N <= 10,000)分钟的晨跑. 在每分钟的开始 ...
- 【USACO】青铜莲花池[2]
前言 搜索到这篇文章的朋友,那么很巧了,我们多半是一个学校的,为什么呢?因为这道题叫白银莲花池.. 题目 [问题描述] FJ建造了一个美丽的池塘,用于让奶牛们锻炼.这个长方形的池子被分割成了 M 行和 ...
- 【USACO】2017 December Contest, Platinum题解
[比赛经历] 大概顺利满分了,就是T2的代码比较难调. T2能够直观地反映出GDB和输出调试结合的优越性. [T1]Standing Out from the Herd [题目链接] 点击打开链接 [ ...
- 【算法】【题解】【usaco】 最受欢迎的牛
[例题] 每头牛都有一个梦想:成为一个群体中最受欢迎的名牛!在一个有N(1<=N<=10,000)头牛的牛群中,给你M(1<=M<=50,000)个二元组(A,B),表示A认为 ...
最新文章
- C#中处理XML文档的方法
- PCI与PXI的区别
- Caffe学习系列(6):Blob,Layer and Net以及对应配置文件的编写
- MINIST深度学习识别:python全连接神经网络和pytorch LeNet CNN网络训练实现及比较(三)...
- Lync Server 2013企业版部署系列之九:前端部署后续工作
- [Leedcode][JAVA][面试题 01.07][找规律][旋转数组]
- 2017.3.9 Harry and Christmas tree 失败总结
- python处理excel的方法有哪些_Python操作Excel简单方法
- # 华为考试心路历程#一名小白的HCNP数通取证记录
- 面向对象编程方法-抽象
- word20161210
- 110道 MySQL面试题及答案 (持续更新)
- python 爬取网易云音乐歌单
- 计算机主机内部配件有哪些,[计算机维护常识]主机内部有哪些附件
- c语言lookup函数怎么用,lookup函数的使用方法,lookup函数怎么用?
- Python 图片转pdf
- 安装ubuntu系统16.04版本
- Python实例6: 贺卡制作
- 量化分析入门7:获取多支股票的收盘价
- Japan POJ - 3067