hdu 1969 二分

题意是给你n个饼的半径  每个人  问没人最大能获得多少    每个人得到的必须是一样多

#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;

#define pi  acos(-1.0)
#define exp 1e-6
int n;
double num[10010];
int judge(double pp)
{
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        double area=num[i];
        while(area>=pp)
        {
            sum++;
            area-=pp;
        }
    }
    return sum;
}
int main()
{
    int m,i,j,T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        double right=-1,left,mid;
        for(i=1;i<=n;i++)
        {
            scanf("%lf",&num[i]);
            num[i]=pi*num[i]*num[i];
            if(num[i]>right) right=num[i];
        }
        sort(num+1,num+1+n);
        left=0;
        while(right-left>=exp)
        {
            mid=(left+right)/2;
            if(judge(mid)>m) left=mid;
            else right=mid;
        }
        printf("%.4lf\n",left);
    }
    return 0;
}
时间: 2024-08-16 14:15:10

hdu 1969 二分的相关文章

hdu 2255 二分图带权匹配 模板题

模板+注解在 http://blog.csdn.net/u011026968/article/details/38276945 hdu 2255 代码: //KM×î´ó×îСƥÅä #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; #define INF 0x0fffffff const int MAXN

Hdu 2389 二分匹配

题目链接 Rain on your Parade Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 655350/165535 K (Java/Others)Total Submission(s): 2644    Accepted Submission(s): 823 Problem Description You’re giving a party in the garden of your villa by the sea. T

hdu 4737 二分或暴力

http://acm.hdu.edu.cn/showproblem.php?pid=4737 Problem Description There are n numbers in a array, as a0, a1 ... , an-1, and another number m. We define a function f(i, j) = ai|ai+1|ai+2| ... | aj . Where "|" is the bit-OR operation. (i <= j)

HDU 3656 二分+dlx判定

Fire station Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1308    Accepted Submission(s): 434 Problem Description A city's map can be seen as a two dimensional plane. There are N houses in

HDU 1969 (二分)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4547    Accepted Submission(s): 1837 Problem Description My birthday is coming up and tra

hdu 1969 Pie(二分查找)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4513    Accepted Submission(s): 1819 Problem Description My birthday is coming up and trad

HDU 1969 Pie 二分

1.题意:一项分圆饼的任务,一堆圆饼共有N个,半径不同,厚度一样,要分给F+1个人.要求每个人分的一样多,圆饼允许切但是不允许拼接,也就是每个人拿到的最多是一个完整饼,或者一个被切掉一部分的饼,要求你算出每人能分到的饼的体积最大值.输入数据依次给出,测试数据组数T,每组数据中,给出N,F,以及N个圆饼的半径.输出最大体积的数值,精确到小数点后四位. 2.分析:一看是这种输出就知道用二分写会很高效,这里对"能分出的最大体积值"进行二分.首先,这个值有界,最大值为总体积除以总人数的值,即Σ

HDU 1969 Pie (二分查找)

题目链接:click here~~ 题目大意:n块馅饼分给m+1个人,每一个人的馅饼必须是整块的.馅饼能够被切开.但不能组合,也不一定要所有分完,问你每一个人最大能分到多大体积的馅饼面积. [解题思路]:二分,对于每一个V值,我们枚举相应情况下人数P的多少,发现是单调递减的,因此二分查找区间,初始值left=0,right=inf;然后judge函数推断当前mid值是否能使得p>=m,因此累计ans=num[i]/mid,写的时候二分用的是while推断,怎么调试答案就是差了那么一点点.后来索性

hdu 1969 Pie(贪心+二分查找)(简单)

Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5628    Accepted Submission(s): 2184 Problem Description My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I