社区讨论
75分 WA on #5
P1016[NOIP 1999 普及组/提高组] 旅行家的预算参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mkj3fdq4
- 此快照首次捕获于
- 2026/01/18 10:04 上个月
- 此快照最后确认于
- 2026/01/21 16:00 4 周前
CPP
#include<bits/stdc++.h>
using namespace std;
struct oil
{
double p,d;
}a[10];
double s,c,l;
double ans=0;
double nowc;//表示当前油量
double cd[10];
int n;
bool cmp(oil x,oil y)
{
return x.d<y.d;
}
int main()
{
cin>>s>>c>>l>>a[0].p>>n;
for(int i = 1;i <= n;i++)
{
cin>>a[i].d>>a[i].p;
}
sort(a+1,a+n+1,cmp);
for(int i = 1;i <= n;i++)
{
cd[i]=a[i].d-a[i-1].d;
}
a[n+1].d=s;
cd[n+1]=s-a[n].d;
for(int i = 1;i <= n+1;i++)//判断能否到达
{
if(cd[i]>c*l)
{
cout<<"No Solution";
return 0;
}
}
for(int i = 0;i <= n;i++)
{
int nextlower;//到达终点一定比他便宜
double distancelower;//距离
for(int j = i+1;j <= n+1;j++)
{
if(a[j].p<a[i].p)//比当前便宜
{
nextlower=j;
break;
}
}
distancelower=a[nextlower].d-a[i].d;
//可以直接一口气冲到下一个比当前便宜的加油站
//把油加到刚刚好到地
if(distancelower<=c*l)
{
// cout<<nowc<<" "<<distancelower<<"\n";
ans+=max(1.0*distancelower/l-nowc,0.0)*a[i].p;
nowc=0;
i=nextlower-1;
nowc=0;
}
else //把油加满,
{
ans+=(c-nowc)*a[i].p;
nowc=c-cd[i+1]/l;
}
}
printf("%.2f",ans);
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...