BZOJ 3893 Cow Jog
Description
The cows are out exercising their hooves again! There are \(N\) cows jogging on an infinitely-long single-lane track \((1 \le N \le 10^{5})\). Each cow starts at a distinct position on the track, and some cows jog at different speeds. With only one lane in the track, cows cannot pass each other. When a faster cow catches up to another cow, she has to slow down to avoid running into the other cow, becoming part of the same running group. The cows will run for \(T\) minutes \((1 \le T \le 10^{9})\). Please help Farmer John determine how many groups will be left at this time. Two cows should be considered part of the same group if they are at the same position at the end of \(T\) minutes.
在一条无限长的跑道上有\(N\)头牛,每头牛有自己的初始位置及奔跑的速度。牛之间不能互相穿透。当一只牛追上另一只牛时,它不得不慢下来,成为一个群体。求\(T\)分钟后一共有几个群体。
Input
The first line of input contains the two integers \(N\) and \(T\). The following \(N\) lines each contain the initial position and speed of a single cow. Position is a nonnegative integer and speed is a positive integer; both numbers are at most \(1\) billion. All cows start at distinct positions, and these will be given in increasing order in the input.
Output
A single integer indicating how many groups remain after \(T\) minutes.
Sample Input
5 3
0 1
1 2
2 3
3 2
6 1
Sample Output
3
这道题其实不是特别难想(但我TMD还是想WA了。。。QAQ)。
思考一下,如果对于某个奶牛\(p\),如果\(p-1,p-2,...,p-i\)都能追上\(p\),那么这些奶牛在最后都能成为一个整体;否则如果中间有一个\(p-j\)断开了,这个就无法与\(p\)成为一个整体,在\(p-j\)前面也没办法。所以对于\(p-j\)重新考虑。
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef long long ll;
#define maxn (100010)
#define eps (1e-7)
int N,T,ans,s[maxn],v[maxn];
int main()
{
freopen("3893.in","r",stdin);
freopen("3893.out","w",stdout);
scanf("%d %d",&N,&T);
for (int i = 1;i <= N;++i) scanf("%d %d",s+i,v+i);
for (int i = N;i >= 1;)
{
int p = i; ans++;
for (--i;i&&(s[p]-s[i])<=(ll)(v[i]-v[p])*(ll)T;--i);
}
printf("%d",ans);
fclose(stdin); fclose(stdout);
return 0;
}
BZOJ 3893 Cow Jog的更多相关文章
- 3893: [Usaco2014 Dec]Cow Jog
3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 174 Solved: 87[Submit] ...
- (寒假集训) Cow Jog(二分优化的最长上升子数列)
Cow Jog 时间限制: 1 Sec 内存限制: 64 MB提交: 24 解决: 5[提交][状态][讨论版] 题目描述 Farmer John's N cows (1 <= N < ...
- [BZOJ 3307]Cow Politics (LCA)
[BZOJ 3307]Cow Politics (LCA) 题面 给出一棵N个点的树,树上每个节点都有颜色.对于每种颜色,求该颜色距离最远的两个点之间的距离.N≤200000 分析 显然对于每种颜色建 ...
- Bzoj3893 [Usaco2014 Dec]Cow Jog
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 302 Solved: 157 Description The cows are out exerci ...
- bzoj 3301 Cow Line
题目大意: n的排列,K个询问 为P时,读入一个数x,输出第x个全排列 为Q时,读入N个数,求这是第几个全排列 思路: 不知道康拓展开是什么,手推了一个乱七八糟的东西 首先可以知道 把排列看成是一个每 ...
- [BZOJ 3363] Cow Marathon
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3363 [算法] 树的直径 [代码] #include<bits/stdc++. ...
- BZOJ 4422 Cow Confinement (线段树、DP、扫描线、差分)
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=4422 我真服了..这题我能调一天半,最后还是对拍拍出来的...脑子还是有病啊 题解: ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- [bzoj3893][Usaco2014 Dec]Cow Jog_暴力
Cow Jog bzoj-3893 Usaco-2014 Dec 题目大意:题目链接. 注释:略. 想法: 先按照坐标排序. 我们发现每个牛只会被后面的牛影响. 所以我们考虑逆向枚举. 记录一下i+1 ...
随机推荐
- Winform 中 DesignMode 返回值不正确的问题。
本文转载:http://blog.csdn.net/sabty/article/details/5325260 以前也曾遇到这样的问题,不过影响不大也没有去详细了解.今天又重新遇到此问题,实在太不便. ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(43)-工作流设计-字段分类设计
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(43)-工作流设计-字段分类设计 系列目录 建立好42节的表之后,每个字段英文表示都是有意义的说明.先建立 ...
- 语音控制的tab选项卡
前端开发whqet,csdn,王海庆,whqet,前端开发专家 ladies and 乡亲们,程序猿同志们,周末仍然坚守工作岗位,或者学习不辍的童鞋们,福音来了. 语音识别高不高端.难不难? 今天给大 ...
- 正则表达式匹配(node.js)
参考文档如下: http://blog.csdn.net/huiguixian/article/details/6131048 http://www.91xueke.com/2013/04/05/30 ...
- listView中的button控件获取item的索引
在listview中的listitem设置事件响应,如果listitem中有button控件,这时候listitem就不会捕获到点击事件,而默认的是listitem中的button会捕获点击事件.那么 ...
- C#获取类中所有方法
var t = typeof(HomeController); //获取所有方法 System.Reflection.MethodInfo[] methods = t.GetMethods(); // ...
- spring-quartz普通任务与可传参任务
两者区别与作用: 普通任务:总调度(SchedulerFactoryBean)--> 定时调度器(CronTriggerFactoryBean) --> 调度明细自定义执行方法bean(M ...
- jacob 操作word
1. 首先下载jacob-1.18.zip,解压后有两个文件jacob.jar 和 jacob.dll.需要把jacob.jar放到你工程的classpath中并且把jacob.dll放到jdk的bi ...
- 2016.7.13final 修饰符使用
final修饰符可以修饰类.变量.函数: 1.被final所修饰的类不能被继承,函数不能被继承,成员变量不能再次被赋值并且被称为常量: 2.被final 修饰的成员变量 .它通常被static所修饰, ...
- 【POJ3243】【拓展BSGS】Clever Y
Description Little Y finds there is a very interesting formula in mathematics: XY mod Z = K Given X, ...