51分求助,玄关
  • 板块P1577 切绳子
  • 楼主cqbzzlr
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/4/27 09:52
  • 上次更新2024/4/27 09:53:01
查看原帖
51分求助,玄关
1238483
cqbzzlr楼主2024/4/27 09:52
#include <bits/stdc++.h>
using namespace std;
int read() {
	int s = 0, w = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') w = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') { 
		s = s * 10 + c - '0';
		c = getchar();
	}
	return s * w;
}
#define fro(n) for(int i=1;i<=n;i++)
const int maxn = 1e8;
double a[maxn];
int n,k;
bool check(double x){
	int sum = 0;
	for(int i = 1;i <= n;i++){
		sum += a[i] / x;
	}
	if(sum >= k) return true;
	else return false;
}
int main() {
	n = read(),k = read();
	fro(n){ 
		a[i] = read();
	}
	double l = 0,r = 1e9;
	while(r - l > 1e-6){
		double mid = (l + r) / 2;
		if(check(mid)) l = mid;
		else r = mid;
	}
	printf("%lf\n",l);
	return 0;
} 
2024/4/27 09:52
加载中...