就是数算不对 75卡住了
查看原帖
就是数算不对 75卡住了
763566
Accepted_please楼主2023/10/9 19:19
#include<iostream>
#include<cstdio>
using namespace std;
pair<double,double> w[20];
double d1,c,d2,p;
double tot=0;
int n;
void ff()
{	
	w[0].first=0;
	w[0].second=p;
	double now_best=p;
	
	if(n==0 && (d1/d2)<=c)
	{
		tot+=(d1/d2)*now_best;
		printf("%.2f\n",tot);
		return; 
	}  	
	else if(n==0 && (d1/d2)>c) 
	{
		printf("No Solution");
		return;
	} 
	/*
	没有加油站 
	d1=275.6 c=11.9 d2=27.4 p=2.8 n=2
    102.0 2.9
    220.0 2.2
    26.95
	*/
	if(w[1].first/d2>c)
	{
		printf("No Solution");
		return;
	}
   	tot+=w[1].first/d2*p;
	for(int i=1;i<=n-1;i++)
	{
		if(w[i+1].first-w[i].first>c*d2)
		{
			printf("No Solution");
			return;
		}
		else if(w[i].second<now_best && c*d2>=w[i+1].first-w[i].first)
		{
			tot+=(w[i+1].first-w[i].first)/d2*w[i].second;
			now_best=w[i].second;
			continue;
		}
		else if(w[i].second>=now_best && c*d2>=w[i+1].first-w[i].first)
		{
			tot+=((w[i+1].first-w[i].first)/d2)*now_best;
		}	   
	} 
	
	tot+=((d1-w[n].first)/d2)*now_best;//最后一短路程 
	printf("%.2f\n",tot);
}

int main()
{
	cin>>d1>>c>>d2>>p>>n;
	for(int i=1;i<=n;i++)	
	{
		cin>>w[i].first>>w[i].second;
	}
	ff();
	return 0;
}
2023/10/9 19:19
加载中...