USACO 2018 February Contest, Silver-Rest Stops

此题探讨了两位徒步者在一条特定长度路径上的行走策略。一位徒步者不允许休息,而另一位可以在预设的休息站停留,目的是最大化休息带来的效益,同时确保两人能够同步完成徒步。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值