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 ...
随机推荐
- 用户浏览器关闭cookie处理方法
方法一: function getSessionId(){ var c_name = "jsessionid"; // alert("cookie:"+docu ...
- android:ImageView 和ImageButton的区别
1.继承不同: java.lang.Object ↳ android.view.View ↳android.widget.ImageView ↳ android.widget.ImageButton ...
- C语言--函数
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenVveW91MTMxNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- Groovy新手教程
Groovy新手教程 kmyhy@126.com 2009-5-13 一.groovy是什么 简单地说,Groovy 是下一代的java语言,跟java一样,它也执行在 JVM 中. 作为跑在JVM ...
- 内部开发环境 git代码托管说明
前言 随着员工的增加 代码的开发版本管理 提上了日程.初步计划: 1 一台机器 192.168.1.240 git代码版本管理 2 运行环境 192.168.1.241 内部开发运行环境 软件工程师 ...
- springmvc 例
1.结构 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaXRscWk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCM ...
- EsayUI datagrid 刷新问题
最近使用esayui 实现前台界面,在对父页面中datagrid列表项进行操作后,如果操作子页面是依附于父页面弹出的窗体,那么调用parent.$("#grid").datagri ...
- .Net4.0如何实现.NET4.5中的Task.Run及Task.Delay方法
前言 .NET4.0下是没有Task.Run及Task.Delay方法的,而.NET4.5已经实现,对于还在使用.NET4.0的同学来说,如何在.NET4.0下实现这两个方法呢? 在.NET4.0下, ...
- Java基础知识强化之集合框架笔记17:List集合的特有的遍历功能
1. List集合的特有遍历功能: size()和 get()方法结合使用 2. 代码示例: package cn.itcast_03; import java.util.ArrayList; imp ...
- Java基础知识强化03:Java中的堆与栈
1.在JVM中,内存分为两个部分,Stack(栈)和Heap(堆),这里,我们从JVM的内存管理原理的角度来认识Stack和Heap,并通过这些原理认清Java中静态方法和静态属性的问题. 一般,JV ...