BZOJ 3893 [Usaco2014 Dec]Cow Jog

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分鐘後一共有幾個羣體。


【題目分析】
思路題目。


【代碼】

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,ans=0;
#define ll long long
ll t,pos,spd,tmp,f[100001];
const ll inf=1e18;
int main()
{
    scanf("%d%lld",&n,&t);
    for (int i=1;i<=n;++i)
    {
        scanf("%lld%lld",&pos,&spd);
        f[i]=pos+t*spd;
    }
    ll tmp=inf;
    for (int i=n;i;--i)
    {
        if (f[i]<tmp)
        {
            ans++;
            tmp=f[i];
        }
    }
    printf("%d\n",ans);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章