码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1969 Pie

时间:2015-07-26 09:44:29      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

二分答案+验证(这题精度卡的比较死)

#include<stdio.h>
#include<math.h>
#define eps 1e-7
const int ff = 11111;
double a[ff];
double pi = acos(-1.0);
int main()
{
    int sb;
    scanf("%d", &sb);
    while (sb--)
    {
        int m, n;
        scanf("%d%d", &m, &n);
        int i, j;
        double maxn = 0;
        for (i = 1; i <= m; i++)
        {
            scanf("%lf", &a[i]);
            a[i] = a[i] * a[i] * pi;
            if (a[i] > maxn) maxn = a[i];
        }
        double minn = 0;
        double midn = (minn + maxn) / 2.0;
        while (1)
        {
            if (maxn - minn < eps)
            {
                printf("%.4lf\n", midn);
                break;
            }
            else
            {
                int sum = 0, flag;
                for (i = 1; i <= m; i++) sum += (int)((1.0*a[i] / midn));
                if (sum >= n+1) flag = 1;
                else flag = 0;
                if (flag) minn = midn, midn = (minn + maxn) / 2.0;
                else maxn = midn, midn = (minn + maxn) / 2.0;
            }
        }
    }
    return 0;
}

 

HDU 1969 Pie

标签:

原文地址:http://www.cnblogs.com/zufezzt/p/4677105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!