有 f + 1 个人来分 n 个圆形派,每个人得到的必须是一整块派,而不是几块拼在一起,并且面积要相同。求每个人最多能得到多大面积的派(不必是圆形)。

这题很好做,使用二分法就OK。

首先在读取所有派的半径后处理出所有派的面积,并且记录最大的那个派的面积。然后从 0 ~ maxsize 二分枚举一下,就能得到答案。

此外,这道题最后输出保留小数位数可以是 3, 4, 5,都可以。

附AC代码:

   1: #include <stdio.h>

   2: #include <math.h>

   3: #include <iostream>

   4: #include <cstdarg>

   5: #include <algorithm>

   6: #include <string.h>

   7: #include <stdlib.h>

   8: #include <string>

   9: #include <list>

  10: #include <vector>

  11: #include <map>

  12: #define LL long long

  13: #define M(a) memset(a, 0, sizeof(a))

  14: using namespace std;

  15: void Clean(int count, ...)

  16: {

  17:     va_list arg_ptr;

  18:     va_start (arg_ptr, count);

  19:     for (int i = 0; i < count; i++)

  20:         M(va_arg(arg_ptr, int*));

  21:     va_end(arg_ptr);

  22: }

  23:  

  24: const double PI = acos(-1.0);

  25: double buf[10009];

  26: int n, f;

  27:  

  28: bool Deal(double size)

  29: {

  30:     int res = 0;

  31:     for (int i = 1; i <= n; i++)

  32:         res += floor(buf[i] / size);

  33:     return (res >= (f + 1));

  34: }

  35:  

  36: int main()

  37: {

  38:     int T;

  39:     scanf("%d", &T);

  40:     while (T--)

  41:     {

  42:         double m = -1;

  43:         scanf("%d%d", &n, &f);

  44:         for (int i = 1; i <= n; i++)

  45:         {

  46:             int r;

  47:             scanf("%d", &r);

  48:             buf[i] = PI * r * r;

  49:             m = max(m, buf[i]);

  50:         }

  51:         double tmp = 0.0;

  52:         while (m - tmp > 1e-5)

  53:         {

  54:             double p = (m + tmp) / 2.0;

  55:             if (Deal(p)) tmp = p;

  56:             else m = p;

  57:         }

  58:         printf("%.5lf\n", tmp);

  59:     }

  60:     return 0;

  61: }

LA 3635 Pie 派 NWERC 2006的更多相关文章

  1. UVA 12097 LA 3635 Pie(二分法)

    Pie My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a numbe ...

  2. LA 3635 Pie

    题意:给出n个圆,分给n+1个人,求每个人最多能够得到多大面积的圆 二分每个人得到的圆的面积 #include<iostream> #include<cstdio> #incl ...

  3. 集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096)

    集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096) 题目描述 有一个专门为了集合运算而设计的"集合栈"计算机.该 ...

  4. Java实现派(Pie, NWERC 2006, LA 3635)

    题目 有F+1个人来分N个圆形派,每个人得到的必须是一整块派,而不是几块拼在一起,且面积要相同.求每个人最多能得到多大面积的派(不必是圆形). 输入的第一行为数据组数T.每组数据的第一行为两个整数N和 ...

  5. Uva 派 (Pie,NWERC 2006,LA 3635)

    依然是一道二分查找 #include<iostream> #include<cstdio> #include<cmath> using namespace std; ...

  6. LA 3635 派

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  7. UVALive 3635 Pie 切糕大师 二分

    题意:为每个小伙伴切糕,要求每个小盆友(包括你自己)分得的pie一样大,但是每个人只能分得一份pie,不能拿两份凑一起的. 做法:二分查找切糕的大小,然后看看分出来的个数有没有大于小盆友们的个数,它又 ...

  8. UVa Live 3635 - Pie 贪心,较小的可能不用 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  9. UVaLive 3635 Pie (二分)

    题意:有f+1个人来分n个圆形派,每个人得到的必须是一个整块,并且是面积一样,问你面积是多少. 析:二分这个面积即可,小了就多余了,多了就不够分,很简单就能判断. 代码如下: #pragma comm ...

随机推荐

  1. JS中基本类型与包装类型的关系

    对于JS中一些类型的转化的东西,自己测试并得出的结论,有错误的地方请大大们留言. 不多废话,直接贴代码,测试请直接拷贝全部代码: <!DOCTYPE html> <html> ...

  2. 网络处理2-异步POST请求和同步请求

    一.异步POST请求 假如请求路径是http://192.168.1.102:8080/MJServer/login,请求参数有2个: username :母鸡 pwd :123 1.POST请求细节 ...

  3. Delphi是座宝山,有待挖掘

    Delphi是座宝山,有待挖掘1. VCL源码是座宝山,把纷繁复杂的Windows编程封装到短短几个类里,不超过8000行代码,还额外包括许多其它的技巧2. RTL是座宝山,方便程序员使用底层运算,不 ...

  4. C#枚举硬件设备(升级版)

    原文:C#枚举硬件设备(升级版) 先取设备类型: ; } }

  5. Phalanx--hdu2859(dp 最大对称子图)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 题意就是给你一个n*n的字符矩阵,从中选出一个最大的子矩阵(m*m)满足关于斜对角线(左下角到右 ...

  6. iOS xcode缓存问题

    Question: When I try to build my app in Xcode, I get this error message:PCH file built from a differ ...

  7. iOS 解析手势识别(Gesture Recognizers)

    一.Gesture Recognizers Gesture Recognizers是在iOS3.2引入的,可以用来识别手势.简化定制视图事件处理的对象.Gesture Recognizers的基类为U ...

  8. MyBatis学习总结_11_MyBatis动态Sql语句

    MyBatis中对数据库的操作,有时要带一些条件,因此动态SQL语句非常有必要,下面就主要来讲讲几个常用的动态SQL语句的语法 MyBatis中用于实现动态SQL的元素主要有: if choose(w ...

  9. Android SQLite数据库增删改查操作

    一.使用嵌入式关系型SQLite数据库存储数据 在Android平台上,集成了一个嵌入式关系型数据库——SQLite,SQLite3支持NULL.INTEGER.REAL(浮点数字). TEXT(字符 ...

  10. AdventureWorksDW2008R2 attach: Unable to open the physical file. Operating system error 5: "5(Access is denied.)

    http://stackoverflow.com/questions/26014133/adventureworksdw2008r2-attach-unable-to-open-the-physica ...