UVALive 3635 Pie(二分法)

简单的二分法应用,循环1000次精度就满足要求了。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const double eps=1e-10;
const int INF=1000000000;
const int maxn=10000+10;
const double pi=acos(-1);
int N,F,T;
double r[maxn],maxr,s[maxn];
bool ok(double x)
{
    int f=0;
    for(int i=0;i<N;i++)
    {
        f+=(int)(s[i]/x);
        if(f>=F) return true;
    }
    return false;
}
int main()
{
    //freopen("in1.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&N,&F);
        maxr=-1;
        F++;
        for(int i=0; i<N; i++)
        {
            scanf("%lf",&r[i]);
            maxr=max(r[i],maxr);
            s[i]=r[i]*r[i]*pi;
        }

        double L=0,R=maxr*maxr*pi;
        for(int i=0;i<1000;i++)
        {
            double m=(L+R)/2;
            if(ok(m)) L=m;
            else R=m;
        }
        printf("%.4lf\n",R);
    }
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}
时间: 2024-07-30 23:24:04

UVALive 3635 Pie(二分法)的相关文章

UVALive - 3635 - Pie(二分)

题意:有F + 1(1 <= F <= 10000)个人分N(1 <= N <= 10000)个圆形派,每个人得到的派面积相同,且必须是一整块(不能够两个甚至多个派拼在一起),求每个人最多能得到多大面积的派.(误差最多到0.001) 因为答案是小数类型的,并且N高达10000,故不可暴力枚举. 可以二分枚举最大面积,然后检查是否切出来派的总个数大于等于F + 1. (判相等时不可直接判相等,需要加精度控制) #include<cstdio> #include<cs

uvalive 3635 Pie

https://vjudge.net/problem/UVALive-3635 题意: 有F+1个人要分n个蛋糕,他们得到的蛋糕的面积必须是一样的,但是每个蛋糕必须是整块的蛋糕,而不是有多块蛋糕拼成的,蛋糕的形状也可以不相同. 给出n块蛋糕各自的半径,求他们每个人能得到的蛋糕的最大面积. 思路: 使得最小值最大,那显然是二分. 二分半径,计算面积,然后枚举每个蛋糕,计算每个蛋糕可以分出来的当前面积的蛋糕会有多少个,总数是否大于等于F+1即可. 记住计算个数的时候要用floor向下取整函数,而且l

LA 3635 - Pie 【二分】

Regionals 2006 >> Europe - Northwestern 3635 - Pie Time limit: 3.000 seconds My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are com

Num 23 : HDOJ : 2199 Can you solve this equation? + HDOJ : 1969 Pie [ 二分法 ]

在处理计算数学上某函数零点的时候,我们通常是这样做的: 1. 先判断这个零点在某个单调区间 [ a,b ]上( 假设为递增区间 ): 2. 之后判断 f(x) 在 (a+b)/2 [ a,b中点处 ]是否为零: 3. 若中点处大于零,b=( a+b )/2 ;否则,同理,a=( a+b )/2 ; 4. 重复2.3.过程,直到找到零点,或满足精度: 如图( 图片来自百度 ): C语言基于这个原理,也有了自己的二分法: 二分法:     在某一特定的序列之中[ 通常是已经排过序的数列 ]寻找某一特

LA 3635 Pie

二分答案 找到最大的圆的面积作为每个人可能分到的最大的面积. 对每个人可能分到的面积二分 验算时,求出每个pie可以切出的最大块数,然后总的块数和需要的块数比较 PS:(就是精度恶心) #include <map> #include <cmath> #include <cstdio> #include <vector> #include <string> #include <cstring> #include <algorith

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU 1969 Pie(二分法)

My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece