洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver
题目描述
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.
输入输出样例
5 3
0 1
1 2
2 3
3 2
6 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;
}
洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver的更多相关文章
- 洛谷P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver
		
传送门 题目大意:n头牛在单行道n个位置,开始用不同的速度跑步. 当后面的牛追上前面的牛,后面的牛会和前面的牛以一样的速度 跑,称为一个小团体.问:ts后有多少个小团体. 题解:模拟 倒着扫一遍,因为 ...
 - 洛谷P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 性质分析
		
Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ...
 - 洛谷 3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题解
		
本蒟蒻又来发题解了, 一道较水的模拟题. 题意不过多解释, 思路如下: 在最开始的时候求出每头牛在t秒的位置(最终位置 然后,如果后一头牛追上了前一头牛,那就无视它, 把它们看成一个整体. else ...
 - luogu P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver |贪心+模拟
		
有N (1 <= N <= 100,000)头奶牛在一个单人的超长跑道上慢跑,每头牛的起点位置都不同.由于是单人跑道,所有他们之间不能相互超越.当一头速度快的奶牛追上另外一头奶牛的时候,他 ...
 - LUOGU P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver
		
传送门 解题思路 比较简单的一道思路题,首先假设他们没有前面牛的限制,算出每只牛最远能跑多远.然后按照初位置从大到小扫一遍,如果末位置大于等于前面的牛,那么就说明这两头牛连一块了. 代码 #inclu ...
 - luogu3111 [USACO14DEC]牛慢跑Cow Jog_Sliver
		
题目大意 有N (1 <= N <= 100,000)头奶牛在一个单人的超长跑道上慢跑,每头牛的起点位置都不同.由于是单人跑道,所有他们之间不能相互超越.当一头速度快的奶牛追上另外一头奶牛 ...
 - 洛谷P2901 [USACO08MAR]牛慢跑Cow Jogging
		
题目描述 Bessie has taken heed of the evils of sloth and has decided to get fit by jogging from the barn ...
 - 洛谷P3045 [USACO12FEB]牛券Cow Coupons
		
P3045 [USACO12FEB]牛券Cow Coupons 71通过 248提交 题目提供者洛谷OnlineJudge 标签USACO2012云端 难度提高+/省选- 时空限制1s / 128MB ...
 - 洛谷——P2952 [USACO09OPEN]牛线Cow Line
		
P2952 [USACO09OPEN]牛线Cow Line 题目描述 Farmer John's N cows (conveniently numbered 1..N) are forming a l ...
 
随机推荐
- ArchLinux 音乐播放客户端ncmpcpp和服务端mpd的配置
			
Ncmcpp是一个mpd客户端,它提供了很多方便的操作 MPD是一个服务器-客户端架构的音频播放器.功能包括音频播放, 播放列表管理和音乐库维护,所有功能占用的资源都很少. --取自 wiki.arc ...
 - 参考《深度学习之PyTorch实战计算机视觉》PDF
			
计算机视觉.自然语言处理和语音识别是目前深度学习领域很热门的三大应用方向. 计算机视觉学习,推荐阅读<深度学习之PyTorch实战计算机视觉>.学到人工智能的基础概念及Python 编程技 ...
 - Java基础学习总结(15)——java读取properties文件总结
			
一.java读取properties文件总结 在java项目中,操作properties文件是经常要做的,因为很多的配置信息都会写在properties文件中,这里主要是总结使用getResource ...
 - [Python] Generating random numbers using numpy lib
			
import numpy as np def test_run(): data=np.random.random((3,4)) """ [[ 0.80150549 0.9 ...
 - iPad popView封装
			
仿照UITableView的UITableViewDataSource 协义 1.代理.让代理帮我们类完毕一些方法 2.完毕当前类不能完毕的事情还有传值等功能 实现方法 // 1. 声明一个协议 // ...
 - VC双缓冲画图技术介绍
			
双缓冲画图,它是一种主要的图形图像画图技术.首先,它在内存中创建一个与屏幕画图区域一致的对象,然后将图形绘制到内存中的这个对象上,最后把这个对象上的图形数据一次性地拷贝并显示到屏幕上. 这样的技术能够 ...
 - vue19  组建 Vue.extend  component、组件模版、动态组件
			
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
 - BZOJ2020: [Usaco2010 Jan]Buying Feed II
			
[传送门:BZOJ2020] 简要题意: 约翰开车回家,遇到了双十一节,那么就顺路买点饲料吧.回家的路程一共有E 公里,这一路上会经过N 家商店,第i 家店里有Fi 吨饲料,售价为每吨Ci 元.约翰打 ...
 - thinkphp使后台的字体图标显示异常
			
thinkphp使后台的字体图标显示异常 相似问题 1.thinkPHP的这些图标都不显示了-CSDN论坛https://bbs.csdn.net/topics/391823415 解答: 发现在别的 ...
 - vue --- cli build 后的项目,图片路径出错
			
今天在插入背景图片过程中,遇到了路径错误的问题,通过网上查询,找到了解决的办法,但是大部分都没有讲造成这种问题的原因,故我简单地总结了一下,并加入了一些自己的理解,欢迎共同探讨~ 当用vue-cli自 ...