旅行家的预算求助!!!
查看原帖
旅行家的预算求助!!!
763566
Accepted_please楼主2023/10/12 18:31
#include<iostream>
#include<cstdio>
using namespace std;

pair<long double,long double> w[20];

long double d1,c,d2,p;
long double tot=0;
int n;
void ff()
{	
	long double now_best=p;
	if(n==0 && (d1/d2)<=c)//能走到 
	{
		tot+=(d1/d2)*p;
		printf("%.2Lf\n",tot);
		return; 
	}  	
	else if(n==0 && (d1/d2)>c)//走不到 
	{
		printf("No Solution");
		return;
	} 
	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)
		{
			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)
		{
			tot+=((w[i+1].first-w[i].first)/d2)*now_best;
		}	   
	} 
	if(d1-w[n].first>c*d2)
	{
		cout<<"No Solution"<<endl;
		return;
	} 
	else if(w[n].second<now_best)
	{
		tot+=((d1-w[n].first)/d2)*w[n].second;
	}
	else
	{
		tot+=((d1-w[n].first)/d2)*now_best;
	}
	printf("%.2Lf\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/12 18:31
加载中...