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. Datagridview 实现二维表头和行合并【转载】

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; u ...

  2. Hadoop平台提供离线数据和Storm平台提供实时数据流

    1.准备工作 2.一个Storm集群的基本组件 3.Topologies 4.Stream 5.数据模型(Data Model) 6.一个简单的Topology 7.流分组策略(Stream grou ...

  3. iOS UI控件继承关系图

    闲来无事,把UI控件的继承关系图整理下来,供自己和大家使用.

  4. PhalGo-介绍

    PhalGo-介绍 phalgo是一个Go语言的一体化开发框架,主要用于API开发应为使用ECHO框架作为http服务web程序一样可以使用,牛顿曾经说过"如果我比别人看得远,那是因为我站在 ...

  5. js substr和substring字符串截取

    substr(start,length)第一个参数是开始位置(注:start的开始是从0开始,看到好多博客上面是从1开始,在火狐和谷歌执行了一下是从0开始),第二个参数是截取字符串的长度(可以省略,表 ...

  6. Log4j(1.2.17) - hello world

    1. Maven 依赖 <dependencies> <dependency> <groupId>log4j</groupId> <artifac ...

  7. reactjs 入门

    地址搜集:http://www.cocoachina.com/webapp/20150604/12035.html class 属性需要写成 className ,for 属性需要写成 htmlFor ...

  8. 非常不错的ASP操作数据库类,支持多数据库MSSQL,ACCESS,ORACLE,MYSQL等

    可同时操作多个不同类型的数据库. 完全不用考虑数据类型的差别,再也不用想字符型字段加不加单引号. 调用非常简单,对数据库的主要操作一般只需要一行代码. 支持mssql事务回滚. 可自动生成和输出sql ...

  9. 类和ID选择器的区别

    学习了类选择器和ID选择器,我们会发现他们之间有很多的相似处,是不是两者可以通用呢?我们不要着急先来总结一下他们的相同点和不同点: 相同点:可以应用于任何元素不同点: 1.ID选择器只能在文档中使用一 ...

  10. 解决js浮点数计算bug

    1.加 function add(a, b) { var c, d, e; try { c = a.toString().split(".")[1].length; } catch ...