求助WA#5
查看原帖
求助WA#5
638630
WindrelAppoad楼主2022/8/26 19:24
#include<bits/stdc++.h>
using namespace std;
double d1,c,d2,sp,ans;
int n;
double d[10005],p[10005];
bool check=0;
void f(int sta,double cos,double left)
{
	if(sta>=n+1)
	{
		check=1;
		ans=cos;
	}
else{
	double dis=d[sta]+d2*c;
	if(dis>=d[sta+1])
	{
	bool che=0;
	int next,mini=0x3f3f3f;
	for(int i=sta+1;d[i]<=dis;i++) 
	 {
	 	if(p[i]<=mini){
			mini=p[i];
			next=i;
		}
		if(p[i]<p[sta])
		{
			che=1;
			next=i;
			break;
		}
	 }
	if(che)
	 { 
	    cos+=p[sta]*((d[next]-d[sta])/d2-left);
	    left=0;
	 }
	else
	 {
	 	cos+=p[sta]*(c-left);
	 	left=c-(d[next]-d[sta])/d2;
	 }
	f(next,cos,left);
    }
    else return;
}
}
int main(){
	scanf("%lf%lf%lf%lf%d",&d1,&c,&d2,&sp,&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lf%lf",&d[i],&p[i]);
	}
	p[0]=sp;
	d[n+1]=d1;
	f(0,0,0);
	if(check) {
		int ansd=(ans+0.005)*100;
		ans=ansd/100.0;
		printf("%.2lf",ans);
	}
	else cout<<"No Solution";
	return 0;
}

死了好几次了

2022/8/26 19:24
加载中...