http://www.elijahqi.win/2018/03/06/luogu4266-usaco18febrest-stops/
题目描述
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
L
L meters (
1 \leq L \leq 10^6
1≤L≤106 ). Farmer John will hike the trail at a constant travel rate of
r_F
rF seconds per meter (
1 \leq r_F \leq 10^6
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
N rest stops along the trail (
1 \leq N \leq 10^5
1≤N≤105 ); the
i
i -th stop is
x_i
xi meters from the start of the trail (
0 < x_i < L
0
#include<cstdio>
#include<algorithm>
#define ll long long
#define N 1100000
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0,f=1;char ch=gc();
while(ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=gc();}
while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=gc();
return x*f;
}
ll l,n,rf,rb;int top;
struct node{int p;ll c;}da[N],q[N];
inline bool cmp(const node &a,const node &b){return a.p<b.p;}
int main(){
// freopen("reststops.in","r",stdin);
// freopen("reststops.out","w",stdout);
l=read();n=read();rf=read();rb=read();
for (int i=1;i<=n;++i) da[i].p=read(),da[i].c=read();
sort(da+1,da+n+1,cmp);ll ans=0;int lm=0;
for (int i=n;i;--i){
if (da[i].c>lm) q[++top]=da[i],lm=da[i].c;
}
for (int i=top;i;--i) ans+=(rf-rb)*(q[i].p-q[i+1].p)*q[i].c;
printf("%lld",ans);
return 0;
}
本文介绍了一个徒步问题,其中Farmer John和他的训练员Bessie在一条长度为L米的直线上徒步,Farmer John以恒定速度前进,而Bessie可以在特定的N个休息点停留。文章详细描述了如何通过算法找到最优的休息策略。

567

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



