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的更多相关文章

  1. 3893: [Usaco2014 Dec]Cow Jog

    3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 174  Solved: 87[Submit] ...

  2. (寒假集训) Cow Jog(二分优化的最长上升子数列)

    Cow Jog 时间限制: 1 Sec  内存限制: 64 MB提交: 24  解决: 5[提交][状态][讨论版] 题目描述 Farmer John's N cows (1 <= N < ...

  3. [BZOJ 3307]Cow Politics (LCA)

    [BZOJ 3307]Cow Politics (LCA) 题面 给出一棵N个点的树,树上每个节点都有颜色.对于每种颜色,求该颜色距离最远的两个点之间的距离.N≤200000 分析 显然对于每种颜色建 ...

  4. Bzoj3893 [Usaco2014 Dec]Cow Jog

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 302  Solved: 157 Description The cows are out exerci ...

  5. bzoj 3301 Cow Line

    题目大意: n的排列,K个询问 为P时,读入一个数x,输出第x个全排列 为Q时,读入N个数,求这是第几个全排列 思路: 不知道康拓展开是什么,手推了一个乱七八糟的东西 首先可以知道 把排列看成是一个每 ...

  6. [BZOJ 3363] Cow Marathon

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3363 [算法] 树的直径 [代码] #include<bits/stdc++. ...

  7. BZOJ 4422 Cow Confinement (线段树、DP、扫描线、差分)

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=4422 我真服了..这题我能调一天半,最后还是对拍拍出来的...脑子还是有病啊 题解: ...

  8. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  9. [bzoj3893][Usaco2014 Dec]Cow Jog_暴力

    Cow Jog bzoj-3893 Usaco-2014 Dec 题目大意:题目链接. 注释:略. 想法: 先按照坐标排序. 我们发现每个牛只会被后面的牛影响. 所以我们考虑逆向枚举. 记录一下i+1 ...

随机推荐

  1. flipsnap--手机屏幕水平滑动框架

    在很多手机应用中,大家都会见过这样一种效果:当手指横向滑动屏幕时,屏幕上的页面会向左或向右滑动. 下面介绍一下当用HTML5+CSS3开发手机应用时解决这类效果的一款js框架:flipsnap. fl ...

  2. mybatis0207 resultType、resultMap、延迟加载使用场景总结

    延迟加载: 延迟加载实现的方法多种多样,在只查询单表就可以满足需求,为了提高数据库查询性能使用延迟加载,再查询关联信息. mybatis提供延迟加载的功能用于service层. resultType: ...

  3. 基于HTML5的SLG游戏开发( 二):创建HTML5页面

    HTML5游戏的开发过程中是在浏览器上进行运行调试的,所以首先我们需要建立一个html页面. 其中,我们把所有的canvas都放到一个viewporter(视图)里面,因此,在body中放置了一个id ...

  4. label_设置行距、字距及计算含有行间距的label高度

    // //  ViewController.m //  CNBlogs // //  Created by PXJ on 16/5/27. //  Copyright © 2016年 PXJ. All ...

  5. Driving the Activity Lifecycle

    Before Robolectric 2.2, most tests created Activities by calling constructors directly, (new MyActiv ...

  6. Bash远程文件传输命令scp

    备份远程文件(远程——>本地) scp -r 远程用户名@ip:文件绝对路径 本地绝对路径 还原远程文件(本地——>远程) scp -r 本地路径 远程用户名@ip:远程绝对路径 如果SS ...

  7. (转)if语句优化

    一.使用常见的三元操作符  if (foo) bar(); else baz(); ==> foo?bar():baz(); if (!foo) bar(); else baz(); ==> ...

  8. java_Collection 类集

    大体概念

  9. sql根据'/'截取最后的字符串

    filpath字段值:/DataFile/UpLoad/Logo/NoPhoto.jpg select filpath,REVERSE((SUBSTRING(REVERSE(FilPath),0,CH ...

  10. Android 安全性和权限

    自定义权限 permission <permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT& ...