标签:void turn fine can www def double for clu
链接:[Miku](https://www.luogu.com.cn/problem/P1016)‘
贪心,对于每一个点,优先跑到能到的点中第一个价格较原点低的,否则加满油跑到价格最低的一个
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#define dou double
using namespace std;
dou d1,c,d2,pp;
int n;
dou d[7];
dou p[7];
dou v;
double x,y;
double ans=99999999.0;
void dfs(int pos,double co,double le,int f){
if(pos==n+1){
printf("%.2lf",co-le*p[f]);
exit(0);
}
dou vv=d[pos]+v;
for(int i=pos+1;i<=n+1&&d[i]<=vv;++i){
if(p[i]<=p[pos]){
dfs(i,co+double(d[i]-d[pos])/d2*p[pos],le,pos);
return ;
}
}
if(pos+1<=n+1&&d[pos+1]<=vv){
int ppp=pos+1;
for(int i=pos+1;i<=n+1&&d[i]<=vv;++i){
if(p[i]<=p[ppp]){
ppp=i;
}
}
dfs(ppp,co+double(c-le)*p[pos],c-(d[ppp]-d[pos])/d2,pos);
return ;
}
}
int main(){
scanf("%lf%lf%lf%lf%d",&d1,&c,&d2,&pp,&n);
d[0]=0;
p[0]=pp;
v=c*d2;
for(int i=1;i<=n;++i){
scanf("%lf%lf",&d[i],&p[i]);
}
d[n+1]=d1;
dfs(0,0.0,0,0);
printf("No Solution");
return 0;
}
标签:void turn fine can www def double for clu
原文地址:https://www.cnblogs.com/For-Miku/p/13615877.html