洛谷 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 ...
随机推荐
- CF GYM 100781A(菊花图+直径)
题目大意 给出若干颗树用最少的边把它们连成一个无向连通图,同时使图的直径最小.输出最小直径. 题解 我们定义树的半径为(树的直径+1)/2.符合题意的连接方式为.所有树的“中点”连在直径最长的树的中点 ...
- mod_php模式原理探析
1.PHP与Apache工作模式 在传统的LAMP架构中,PHP与Apache交互时,至少有两种方式『运行PHP』: 使用CGI:Apache发送请求至php-cgi进程,php-cgi进程调用PHP ...
- CF 414B Mashmokh and ACM 动态规划
题意: 给你两个数n和k.求满足以下条件的数列有多少个. 这个数列的长度是k: b[1], b[2], ……, b[k]. 并且 b[1] <= b[2] <= …… <= b[k] ...
- What is x86 Conforming Code Segment?
SRC=Microprocessor Based Systems SRC=Computer Architecture: A Quantitative Approach
- 第五章,AsyncTask和ProgressBar的练习(Android)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...
- Linux 6.2配置yum本地
yum 1.挂在iso文件 [root@localhostmedia]# mount /dev/cdrom /media 2.安装createrepo createrepo是配置YUM源的配置工具,检 ...
- BZOJ 1306 DFS
思路: 搜索就好 (注意不要枚举太多东西) //By SiriusRen #include <cstdio> using namespace std; int n,point[10],an ...
- HDU 3374 String Proble
String Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- display 表格模型值
display:inline-table 此元素会作为内联表格来显示(类似 <table>),表格前后没有换行符.display:inline-table 可以使文字和表格在同一行显示 d ...
- HP 1022N 网络打印机安装步骤
HP 1022N 网络打印机安装步骤