也是爆在了#5上
查看原帖
也是爆在了#5上
271544
__polar_ice楼主2024/10/15 21:15

思路:dfs

#include<bits/stdc++.h>

#define float double
using namespace std;
float d1,C,d2,P;int N;
bool isok=false;
float minn=998776554;
struct type{
	float di,pi;
}Point[11];
bool cmp(type a,type b){
	if(a.di!=b.di)return a.di<b.di;
	if(a.pi!=b.pi)return a.pi<b.pi;
}
void dfs(int P/*第x站*/,float exp/*expense*/){
	if(P==N+1){
		minn=min(minn,exp);
		isok=true;return;
	}
	for(int i=P+1;i<=N+1;i++)
		if((Point[i].di-Point[P].di)<C*d2){
			dfs(i,exp+Point[P].pi/d2*(Point[i].di-Point[P].di));
		}
		else return;
			
}
int main(){
	cin>>d1>>C>>d2>>P>>N;
	Point[0].di=0,Point[0].pi=P;
	for(int i=1;i<=N;i++)
		cin>>Point[i].di>>Point[i].pi;
	Point[N+1].di=d1;Point[N+1].pi=0;
	sort(Point+1,Point+N,cmp);
	dfs(0,0);
	if(isok)printf("%.2lf",minn);
	else cout<<"No Solution"; 
	return 0;
}

原输入样例:

475.6 11.9 27.4 14.98 6
102.0 9.99
220.0 13.29
256.3 14.79
275.0 10.29
277.6 11.29
381.8 10.09

原输出样例:

192.15

我的输出:

192.32

疑惑:直观上,感觉从开始到(9.99)(9.99)站加油再到(10.09)(10.09)站加油最后再到终点可以拥有最小花费?
但为什么我以这个算式:102.0÷27.4×14.98+(381.8102.0)÷27.4×9.99+(475.6381.8)÷27.4×10.09102.0\div27.4\times14.98+(381.8-102.0)\div27.4\times9.99+(475.6-381.8)\div27.4\times10.09算出来的结果仍然是192.32192.32呢?

求大佬带飞!!!

2024/10/15 21:15
加载中...