洛谷P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 性质分析

Code:

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 1000000 + 233;
const long long N = 1000000000000000000;
long long pos[maxn], speed[maxn], T , dest[maxn];
int A[maxn], n;
int cmp(int i,int j)
{
    if(dest[i] != dest[j]) return pos[i] < pos[j];
    return dest[i] < dest[j];
}
int main()
{
   //freopen("data.txt","r",stdin);
    scanf("%d%lld",&n,&T);
    for(int i = 1;i <= n; ++i)
    {
        scanf("%lld%lld",&pos[i],&speed[i]);
        dest[i] = pos[i] + speed[i] * T;
        A[i] = i;
    }
    sort(A + 1, A + 1 + n, cmp);
    int ans = 0;
    long long cur = N;
    for(int i = n;i >= 1; --i)
    {
        if(dest[A[i]] < cur)
        {
            ++ans;
            cur = dest[A[i]];
        }
    }
    printf("%d",ans);
    return 0;
}
posted @ 2018-09-17 18:48  EM-LGH  阅读(163)  评论(0编辑  收藏  举报