蒟蒻求助
  • 板块P1577 切绳子
  • 楼主Nervegas
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/10/14 22:09
  • 上次更新2024/10/15 10:50:36
查看原帖
蒟蒻求助
1206518
Nervegas楼主2024/10/14 22:09

代码WA#8,我的输出为0.99,而答案是1.00,题目中不是说答案与标准答案误差不超过 0.01 0.01 或者相对误差不超过 1 % 1% 即可通过吗? 代码如下

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, k;
double a[N];
double l, r;
char s[100];
inline bool check(double x){
	int cnt = 0;
	for(int i = 1 ; i <= n ; i++) cnt += (a[i] / x);
	return cnt >= k;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin >> n >> k;
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i];
		r += a[i];
	}
	while(r - l > 1e-4){
		double mid = (l + r) / 2.0;
		if(check(mid)) l = mid;
		else r = mid;
	}
	printf("%.2f\n", floor(l * 100) / 100);
	return 0;
}
2024/10/14 22:09
加载中...