洛谷 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 ...
随机推荐
- who---显示目前登录系统的用户信息
who命令是显示目前登录系统的用户信息.执行who命令可得知目前有那些用户登入系统,单独执行who命令会列出登入帐号,使用的终端机,登入时间以及从何处登入或正在使用哪个X显示器. 语法 who(选项) ...
- 内存,寄存器和cache的区别与联系
1. 寄存器是中央处理器内的组成部份.寄存器是有限存贮容量的高速存贮部件,它们可用来暂存指令.数据和位址.在中央处理器的控制部件中,包含的寄存器有指令寄存器(IR)和程序计数器(PC).在中央处理器的 ...
- HDU——T 3342 Legal or Not
http://acm.hdu.edu.cn/showproblem.php?pid=3342 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- 分布式文件存储FastDFS(一)初识FastDFS
一.FastDFS简单介绍 FastDFS是一款开源的.分布式文件系统(Distributed File System),由淘宝开发平台部资深架构师余庆开发.作为一个分布式文件系统,它对文件进行管理. ...
- Linux下无需输入password自己主动登陆sshserver方法
用OpenSSH在linux下登陆sshserver时.每次都提示要输入password,并且使用vim 的netrw插件编辑远程文件时每次改动后保存都要输password,很麻烦. 查看了netrw ...
- Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the ser
没有Include wsgi,执行: sudo a2enmod wsgi 可能出现以下的错误 ERROR: Module mod-wsgi does not exist! 安装 libapache2- ...
- 静态时序分析SAT
1. 背景 静态时序分析的前提就是设计者先提出要求,然后时序分析工具才会根据特定的时序模型进行分析,给出正确是时序报告. 进行静态时序分析,主要目的就是为了提高系统工作主频以及增加系统的稳定性.对 ...
- Asp.Net碎知识
在aspx页面 获取值: UserModel user=new UserModel();实例化 user.Address=context["txtAddress"]; 如果前台不需 ...
- js正则学习分享
http://www.cnblogs.com/rubylouvre/archive/2010/03/09/1681222.html http://www.cnblogs.com/tylerdonet/ ...
- 分享一下js正则中惰性与贪婪
首先引入一个介绍比较详细的网站 http://www.cnblogs.com/yuaima/p/5258513.html http://www.jb51.net/article/31491.htm 接 ...