首页 > 其他 > 详细

二分法

时间:2020-01-18 22:13:38      阅读:100      评论:0      收藏:0      [点我收藏+]

技术分享图片

 技术分享图片

 技术分享图片

技术分享图片

 技术分享图片

技术分享图片

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

 

 技术分享图片

技术分享图片

 技术分享图片

 技术分享图片

技术分享图片

技术分享图片

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 1000
#define M 1000
using namespace std;
int n,f;
int a[N];
bool check(int x)
{
    int s=0;
    for(int i=1;i<=n;i++) s+=a[i]/x;
    if(s>=f) return true;
    return false;
}
int main()
{
    cin>>n>>f;
    f++;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    int l=0,r=sum/f;
    while(l<r)
    {
        int mid=(l+r+1)/2;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    cout<<l<<endl;
}

二分法

原文:https://www.cnblogs.com/liusu123456/p/12210148.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!