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

二分int,贴个代码

Posted by ga5397608 at 2013-09-20 13:37:44 on Problem 1064
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

const int maxn = 10005;

int n,k;
double data[maxn];

bool ke(int x)
{
    double div = x/1000.0;
    int cnt = 0;
    for(int i=1;i<=n;++i)
    {
        cnt +=(int)(data[i]/div);
        if(cnt>=k)
            return  1;
    }
    return 0;
}
int main()
{
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        int l = 1,r = 0,res=0;
        for(int i=1;i<=n;++i)
        {
            scanf("%lf",data+i);
            r = max(r,(int)(data[i]*1000));
        }
        while(r>=l)
        {
            int m = (l+r)>>1;
            if(ke(m))
            {
                l = m + 1;
                res = m;
            }
            else
            {
                r = m - 1;
            }
        }
        res -= res%10;
        printf("%.2lf\n",res/1000.0);
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator