题目描述

The cows are out exercising their hooves again! There are N cows

jogging on an infinitely-long single-lane track (1 <= N <= 100,000).

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 <= T <= 1,000,000,000). 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 (1 <= N <= 100,000)头奶牛在一个单人的超长跑道上慢跑,每头牛的起点位置都不同。由于是单人跑道,所有他们之间不能相互超越。当一头速度快的奶牛追上另外一头奶牛的时候,他必须降速成同等速度。我们把这些跑走同一个位置而且同等速度的牛看成一个小组。

请计算T (1 <= T <= 1,000,000,000)时间后,奶牛们将分为多少小组。

输入输出格式

输入格式:

INPUT: (file cowjog.in)

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: (file cowjog.out)

A single integer indicating how many groups remain after T minutes.

输入输出样例

输入样例#1: 复制

5 3
0 1
1 2
2 3
3 2
6 1
输出样例#1: 复制


3
思路:计算最后她所能到达的位置。然后倒序处理。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 100010
using namespace std;
int n,t,ans;
long long last[MAXN];
int main(){
scanf("%d%d",&n,&t);
for(int i=;i<=n;i++){
int pos,v;
scanf("%d%d",&pos,&v);
last[i]=pos+1ll*v*t;
}
ans=;
for(int i=n-;i>=;i--){
if(last[i]>=last[i+])
last[i]=last[i+];
else ans++;
}
cout<<ans;
}

最新文章

  1. angularjs学习使用分享
  2. ZOJ Problem Set - 1365 Mileage Bank
  3. java基于socket的简单聊天系统
  4. 千位分隔符(js 实现)
  5. spring的事务回滚
  6. SharedPreferences实现记住密码功能
  7. C# 线程知识--使用ThreadPool执行异步操作
  8. 【Java基础】Java中的代码块
  9. 使用OpenFileDialog实现图片上传
  10. 在C#实现托盘效果(转)
  11. HDU1257-最少拦截系统
  12. 基于ThinkPHP 5.0与Vue.JS 2.x的前后端开源开发框架VueThink
  13. CVE-2017-7494 Linux Samba named pipe file Open Vul Lead to DLL Execution
  14. javascript 5.2
  15. HDU 2841-Visible Trees 【容斥】
  16. 【iCore4 双核心板_ARM】例程三十六:DAC实验——输出直流电压
  17. 将H5页面的应用打包成APP(苹果和安卓版本)
  18. 创建表时,主键 USING BTREE、USING HASH 的含义(待补充)
  19. 2018.12.21 bzoj3238: [Ahoi2013]差异(后缀自动机)
  20. webstrom git 版本控制

热门文章

  1. LinkedList源码学习
  2. Python对象的循环引用问题
  3. Python对象引用的所有权
  4. php异常处理的深入
  5. vue使用axios中 this 指向问题
  6. WHU 1552 Seats 枚举
  7. 【Henu ACM Round#20 B】Contest
  8. OpenGL 获取当前屏幕坐标对应的三维坐标
  9. ImageLoader的简单分析(二)
  10. POJ 2826 An Easy Problem!(简单数论)