USACO 2018 February Contest, Silver-Rest Stops

G: Rest Stops

时间限制: 1 Sec  内存限制: 128 MB
提交: 97  解决: 38
[提交][状态][讨论版][命题人:admin]

题目描述

Farmer John and his personal trainer Bessie are hiking up Mount Vancowver. For their purposes (and yours), the mountain can be represented as a long straight trail of length LL meters (1≤L≤106). Farmer John will hike the trail at a constant travel rate of rF seconds per meter (1≤rF≤106). Since he is working on his stamina, he will not take any rest stops along the way.
Bessie, however, is allowed to take rest stops, where she might find some tasty grass. Of course, she cannot stop just anywhere! There are N rest stops along the trail (1≤N≤105); the i-th stop is xi meters from the start of the trail (0<xi<L) and has a tastiness value ci (1≤ci≤106). If Bessie rests at stop i for t seconds, she receives ci⋅t tastiness units.

When not at a rest stop, Bessie will be hiking at a fixed travel rate of rB seconds per meter (1≤rB≤106). Since Bessie is young and fit, rB is strictly less than rF.

Bessie would like to maximize her consumption of tasty grass. But she is worried about Farmer John; she thinks that if at any point along the hike she is behind Farmer John on the trail, he might lose all motivation to continue!

Help Bessie find the maximum total tastiness units she can obtain while making sure that Farmer John completes the hike.

输入

The first line of input contains four integers: L, N, rF, and rB. The next N lines describe the rest stops. For each i between 1 and N, the i+1-st line contains two integers xi and ci, describing the position of the i-th rest stop and the tastiness of the grass there.
It is guaranteed that rF>rB, and 0<x1<⋯<xN<L. Note that rF and rB are given in seconds per meter!

输出

A single integer: the maximum total tastiness units Bessie can obtain.

样例输入

10 2 4 3

7 2

8 1

样例输出

15



【题意+思路】

    这是一道贪心题, 但是  题意佶屈聱牙,特别是对于速度的描述蜜汁尴尬,  理解成 m/s   然后 发现根本不可能有答案,

    pppp  才发现是  s/m   每米需要多少秒,

  这样的话,B 保证大于A的情况下,  价值为c*t  那么 c越大 价值就越高, 所以按照价值排序,  

    然后贪心操作

【代码实现】


#include <iostream>
#include <bits/stdc++.h>
 
 
typedef long long ll;
const int MAXN=1e5+10;
const ll INF=0x3f3f3f3f;
using namespace std;
 
struct node{
    ll x,c;
}a[MAXN];
int cmp(node a,node b)
{
    if(a.c==b.c)
        return a.x<b.x;
    return a.c>b.c;
}
int main()
{
    ll l,n,b,f;
    memset(a,0,sizeof(a));
    cin>>l>>n>>f>>b;
    for(int i=1;i<=n;i++)
        cin>>a[i].x>>a[i].c;
 
    int t=(f-b);
    sort(a+1,a+n+1,cmp);
    ll ans=0;
    ll d=0;
    int pre=1;
    ans+=a[1].c*(a[1].x*t);
    for(int i=2;i<=n;i++)
    {
        if(a[i].x>a[pre].x)
        {
            d=a[i].x-a[pre].x;
            ans+=a[i].c*(d*t);
            pre=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}
 
/**************************************************************
    Problem: 5930
    User: ldu_sc08
    Language: C++
    Result: 正确
    Time:160 ms
    Memory:3264 kb
****************************************************************/

123

posted @ 2018-04-03 15:36  Sizaif  阅读(512)  评论(0编辑  收藏  举报