poj---1064---Cable master

题目链接: http://poj.org/problem?id=1064

Mean:

搜索一位巨巨的讲解题意:http://www.cnblogs.com/scau20110726/archive/2013/06/11/3131991.html

在这要特别强调一点poj 和vj并不支持%.2lf今天手贱直接因为这个wa了好几次,因为并不知道是这个错误,记得之前他们告诉我这样是对的,然而并不习惯带l,所以不知道到底对不对

 

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;
typedef long long LL;

const int maxn=100009;
const int INF=0x3f3f3f3f;
const int mod=2009;
double a[maxn];

int main()
{
    int n, m;
    while(~scanf("%d %d", &n, &m))
    {
        double maxx=-1;
        for(int i=0; i<n; i++)
        {
            scanf("%lf", &a[i]);
            maxx=max(maxx, a[i]);
        }

        double l=0, r=maxx*100, mm, ans=0;;
        int mid, sum;

        while(l <= r)
        {
            mid=(l+r)/2;
            sum=0;
            mm=(double)mid/100;

            for(int i=0; i<n; i++)
                sum+=a[i]/mm;

            if(sum < m)
                r=mid-1;
            else
            {
                ans=mid;
                l=mid+1;
            }
        }
        ans/=100;
        if(ans < 0.01)
            printf("0.00\n");
        else
            printf("%.2lf\n", ans);
    }
    return 0;
}

 

posted @ 2016-08-23 15:17  爱记录一切美好的微笑  阅读(130)  评论(0编辑  收藏  举报