求dalao帮忙调一调,不知道为什么程序的结果相差很大
查看原帖
求dalao帮忙调一调,不知道为什么程序的结果相差很大
1266801
wuzhiyuan123楼主2024/2/24 20:31
#include <iostream>
#include <cstdio>
using namespace std;
int s, a, b;
bool f(int c){//计算小车把一人载到c出之后继续在人所用的时间 
	double ac = c / b;
	double bde = (c - ac * a) / (a + b);
	double t1 = ac + (s - c) / a;
	double t2 = ac + bde + (s - (ac + bde) * a) / b;
	return t1 > t2;
}
double fAns(int c){
	double ac = c / b;
	double bde = (c - ac * a) / (a + b);
	double t1 = ac + (s - c) / a;
	double t2 = ac + bde + (s - (ac + bde) * a) / b;
	return t1;
}
int main()
{
	freopen("input.txt", "r", stdin);
	cin >> s >> a >> b;
	int l = 0, r = s, mid, ans = -1e8;
	while(l <= r){
		mid = (l + r)/2;
		if(f(mid)){
			l = mid+1;
			ans = max(mid, ans);
		} 
		else r = mid-1;
	} 
	printf("%.6lf", fAns(ans));
	return 0;
} 
2024/2/24 20:31
加载中...