到底是哪错了?大佬们快来看看,紧急求调!!!
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
struct node1
{
double d;
double p;
};
node1 a[1001];
//a[i].d为出发点与城市i之间的距离,a[0].d表示出发点到终点的距离
//a[i].p表示油站i每升汽油价格,a[0].p表示出发点汽油价格
double c,d2;//c表示汽车油箱的容量,d2表示每升汽油能行驶的距离
int n;//油站个数
bool cmp1(node1 x,node1 y)
{
return x.d<y.d;
}
struct node2
{
double p;//价格
double m;//油量
};
bool cmp2(node2 x,node2 y)
{
return x.p<y.p;
}
node2 b[1001];
double ans=0.00;
int main()
{
cin>>a[0].d>>c>>d2>>a[0].p>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].d>>a[i].p;
}
sort(a+1,a+1+n,cmp1);
b[0].p=a[0].p;
b[0].m=c;
bool flag=false;
int l=0;
for(int i=1;i<=n;i++)
{
if(i==1)
{
ans+=a[i].d/d2*b[l].p;
b[l].m-=a[i].d/d2;
if(b[l].m<0)
{
flag=true;
break;
}
b[i].p=a[i].p;
b[i].m=c-b[i-1].m;
sort(b+l,b+i,cmp2);
while(b[l].m<=0)
{
l++;
}
}
else
{
ans+=(a[i].d-a[i-1].d)/d2*b[l].p;
double t=(a[i].d-a[i-1].d)/d2;
while(t>0)
{
if(l>i)
{
flag=true;
break;
}
if(t>b[l].m)
{
t-=b[l].m;
l++;
}
else
{
b[l].m-=t;
t=0;
}
}
if(flag)
{
break;
}
b[i].p=a[i].p;
b[i].m=c;
for(int j=l;j<i;j++)
{
b[i].m-=b[j].m;
}
sort(b+l,b+i,cmp2);
while(b[l].m<=0)
{
l++;
}
}
}
if(flag)
{
cout<<"No Solution"<<endl;
}
else
{
cout<<ans<<endl;
}
return 0;
}