Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 为什么将初始左端点设置为1就WA呢

Posted by 1069890 at 2019-08-05 23:58:49 on Problem 1064
```#include<iostream>
#include<cstring>
#include<math.h>
#include<stdlib.h>
#include<cstring>
#include<cstdio>
#include<utility>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
long long int n,k;
const int maxn=100005;
const double inf=200005.0;
double ary[maxn];

int div(double x){//每条长度为x可以分为几段
int ans=0;
for(int i=1;i<=n;i++){
ans+=(int)(ary[i]/x);
}
return ans>=k;
}

int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("input.txt","r",stdin);
while(cin>>n>>k){
for(int i=1;i<=n;i++)cin>>ary[i];

sort(ary+1,ary+1+n);
//这里left>0会错。。。
double left=0,right=ary[n];

double mid=0;
for(int i=1;i<=100;i++){
mid=(left+right)/2;
//分割段数过多说明木板长度小，所以这里是左端点
if(div(mid))left=mid;
else right=mid;
}
printf("%.2f\n",floor(left*100)/100);

}
return 0;
}```

Followed by: