后两个点wa了
我这个蒟蒻就是菜……
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
double d1,c,d2;
int n;
//两城市距离,油箱容量,每升油开多远,起始点价格
struct node{
double pos,price;
};
node JiaYouZhan[7];
int nowIndex=0;
double nowDis=0;
double nowPrice = 0;
bool mustRun = false;
bool cmp(node a,node b){
return a.pos<b.pos;
}
int main()
{
node a;
a.pos = 0;
cin >> d1 >> c >> d2 >> a.price >> n;
for(int i = 1;i<=n;i++){
cin>>JiaYouZhan[i].pos>>JiaYouZhan[i].price;
}
JiaYouZhan[0] = a;
sort(JiaYouZhan,JiaYouZhan+n+1,cmp);
while(nowDis<d1){
if(nowIndex==n){
mustRun=true;
}
bool isChangeJiaYouZhan = false;//是否需要换加油站
int nextIndex=nowIndex+1;
if(!mustRun){
if(JiaYouZhan[nextIndex].price>JiaYouZhan[nowIndex].price){
//当下一个加油站的价格大于现在的价格
//double oil = (d1-nowDis)/d2;
//if(oil>c){//把油加满都到不了终点就真的得换了
isChangeJiaYouZhan = true;
double minV=JiaYouZhan[nextIndex].price;
int ind=nextIndex;
//当然换肯定是在可能的范围内要换个最低价的……
for(int i = nextIndex+1;i<=n;i++){
if(JiaYouZhan[i].pos-nowDis<=c*d2){
if(JiaYouZhan[i].price<=minV){
minV = JiaYouZhan[i].price;
ind = i;
}
}
}
nextIndex = ind;
//}
}else{
isChangeJiaYouZhan=true;
}
}
if(isChangeJiaYouZhan){
//当前加油站应该加的油
double oilNowP = (JiaYouZhan[nextIndex].pos-nowDis)/d2;
if(oilNowP>c){//如果连下个加油站都到不了
cout<<"No Solution";
return 0;
}
double priceNowP = oilNowP*JiaYouZhan[nowIndex].price;
nowDis = JiaYouZhan[nextIndex].pos;
nowIndex = nextIndex;
nowPrice += priceNowP;
if(nextIndex==n){
mustRun = true;
}
}else{
double oilNowP = (d1-nowDis)/d2;
if(oilNowP>c){//如果终点到不了
cout<<"No Solution";
return 0;
}
nowDis = d1;
nowPrice+=oilNowP*JiaYouZhan[nowIndex].price;
}
//cout<<nowIndex<<": "<<nowPrice<<" "<<isChangeJiaYouZhan<<endl;
}
printf("%.2lf",nowPrice);
return 0;
}