Description
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头牛,每头牛有自己的初始位置及奔跑的速度。牛之间不能互相穿透。当一只牛追上另一只牛时,它不得不慢下来,成为一个群体。求T分钟后一共有几个群体。
Input
Output
Sample Input
0 1
1 2
2 3
3 2
6 1
Sample Output
HINT
Source
#include<iostream>
#include<cstdio>
using namespace std;
const int N=100005;
int n,ans;
long long t;
bool b[N];
struct node
{
long long pos,spd;
}a[N];
int main()
{
scanf("%d%lld",&n,&t);
for(int i=1;i<=n;i++)
scanf("%lld%lld",&a[i].pos,&a[i].spd);
for(int i=n;i>=1;i--)
if(!b[i])
{
ans++;
for(int j=i-1;j>=1;j--)
if(a[j].spd*t+a[j].pos>=a[i].spd*t+a[i].pos)
b[j]=1;
else
break;
}
printf("%d\n",ans);
return 0;
}
这篇博客介绍了如何解决USACO 2014年12月竞赛中的一道题目,即在一条无限长的跑道上,不同速度的牛在经过T分钟运动后会形成多少个跑步群体。每个群体由位置相同的牛组成,当快牛追上慢牛时,它们会形成一个群体。问题的关键在于通过模拟牛的运动状态来确定最终的群体数量。输入和输出格式、样例输入和输出也在博客中给出。

2167

被折叠的 条评论
为什么被折叠?



