其他分享
首页 > 其他分享> > poj 1064(注意二分搜索变形中l,r,mid的取值和结果取mid还是l 抑或r )

poj 1064(注意二分搜索变形中l,r,mid的取值和结果取mid还是l 抑或r )

作者:互联网

#include<iostream>
#include<cmath>
using namespace std;
int n,k;
int data[10005];
bool check(int len){
    int sum = 0;
    for(int i=0;i<n;i++){
        sum += data[i]/len;
        if(sum>=k)return true; 
    }
    return false;
}
int main(){
    scanf("%d%d",&n,&k);
    double tmp;
    for(int i=0;i<n;i++){
        scanf("%lf",&tmp);
        data[i] = tmp*100;
    }
    int l,r,mid;
    l = 0;r = 10000000;
    while(l<r){
        mid = (l+r+1)/2;
        if(check(mid))l = mid;
        else r = mid-1; 
    }
    printf("%.2f",r/100.0);
    return 0;
}

 

标签:10005,return,int,mid,1064,poj,false,include
来源: https://www.cnblogs.com/stevenzrx/p/15584465.html