有 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. SSH 使用JUnit测试

    前提是引入两个包:org.springframework.test-3.1.3.RELEASE和JUnit4. package com.qk.test; import javax.annotation ...

  2. MyEclipse — Maven+Spring+Struts+Hibernate 整合 [学习笔记-1]

    示例数据库test,用户信息表

  3. SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-003-四种方式获取DataSource

    一.概述 1.Spring offers several options for configuring data-source beans in your Spring application, i ...

  4. Java-马士兵设计模式学习笔记-观察者模式-OOD 封装event

    把小孩醒来时的具体情况封装成事件类 Test.java class WakenUpEvent{ private long time; private String location; private ...

  5. android 点九PNG技术 适应不同分辨率 完美显示效果

    .9.png是一种非失真性压缩位图图形文件格式.PNG格式是非失真性压缩的,允许使用类似于GIF格式的调色板技术,支持真彩色图像,并具备阿尔法通道(半透明)等特性.现在有很多人使用PNG格式于互联网及 ...

  6. iOS 限制UITextField输入字符

    开篇 之前做过一个即时通信的项目,需要限制输入框文本的字符个数,当时从网络上搜寻了几个方法,解决了需求,但是网络上的解决办法不是很全面:今天又遇到一个限制搜索框UISearchBar输入字符个数的问题 ...

  7. How to configure Spring facet in IntelliJ IDEA

    遇到了这个问题,稀里糊涂的就给搞定了,在stackoverfolw上看到了相同的问题,直接拷贝下来吧 Spring Configuration Check Unmapped Spring config ...

  8. Android EditText获取光标位置并插入字符删除字符

    1.获取光标位置 int index = editText.getSelectionStart(); 2.在光标处插入字符 int index = editText.getSelectionStart ...

  9. Jquery正则表达式公式.例子

    1.非负整数         /^\d+$/     2.正整数           /^[0-9]*[1-9][0-9]*$/     3.非正整数       /^((-\d+)|(0+))$/  ...

  10. requirejs 优化压缩

    1 配置node环境 2 配置built.js文档 3 执行命令node r.js -o built.js 文件目录: <!DOCTYPE HTML> <html lang=&quo ...