# 算法第二章作业

2-5 派 (15分)

### 输入样例:

3 3
4 3 3


### 输出样例:

25.133算法描述：
//#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define infll 0x3f3f3f3f3f3f3f3f
#define il inline
#define re register
#define pb push_back
#define db double
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define MP make_pair
#define lowbit(x) x&(-x)
#define fi first
#define se second
{
char ch = getchar();
ll p = 1,data = 0;
while(ch<'0'||ch>'9')
{
if(ch == '-')p = -1;
ch = getchar();
}
while(ch>='0'&&ch<='9')
{
data = data*10+(ch^48);
ch = getchar();
}
return p*data;
}
il ll qpow(ll a,ll b)
{
ll r = 1;
while(b)
{
if(b&1)r = a*r;
a = a*a;
b>>=1;
}
return r;
}
il ll gcd(ll a,ll b)
{
if(!a || !b) return (!a)?b:a;
while(b ^= a ^= b ^= a %= b);
return a;
}
il ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
void exgcd(ll a, ll b, ll &x,ll &y)
{
if(!b) x = 1, y = 0;
else
{
exgcd(b, a % b, y, x);
y -= x * (a / b);
}
}
const int mod = 1e9+7,maxn = 1e4+5;
#define PI acos(-1)
#define eps 1e-4
db a[maxn];
int n,f;
int check(db x)
{
int num = 0;
for(int i = 1; i <= n; i++)
num += floor(a[i]/x);
return num >= f+1;
}
int main()
{
for(int i = 1; i <= n; i++)
db l = 0.0,r = 1e9,mid,ans = 0.0;
while(r-l >= eps)
{
mid = (l+r)/2;
if(check(mid))
l = mid,ans = mid;
else
r = mid;
}
printf("%.3lf\n",ans);
return 0;
}



posted @ 2020-10-31 22:58  Frantatic  阅读(117)  评论(0编辑  收藏  举报