思路和题解一样,double之类的细节也检查过了,还是有几个测试点过不了
查看原帖
思路和题解一样,double之类的细节也检查过了,还是有几个测试点过不了
1268242
EumenidesHe楼主2024/2/26 22:54
#include<iostream>
using namespace std;
const int maxn = 1e5;
int n, p,suma,sumb;
pair<int, int>a[maxn];
bool P(double mid)
{
	double r = p;
	for (int i = 1; i <= n;i++)
	{
		double temp = a[i].first - a[i].second / mid;
		if (temp > 0)r -= temp;
	}
	return r >= 0;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> p;
	for (int i = 1; i <= n; i++)cin >> a[i].first >> a[i].second,suma+=a[i].first;
	if (suma <= p) { cout << -1; return 0; }
	double L = 0, R = 1e300, mid, ans;
	while ((R-L) / max(1.0, mid) >= 1e-4)
	{
		if (P(mid = (L+R)/2))
		{
			L = mid;
		}
		else
		{
			R = mid;
		}
	}
	cout << mid;
}

第11 13 14 15 16 18 20测试点过不了 求助!!! 谢谢谢谢!!!

2024/2/26 22:54
加载中...