LA 3635 Pie 派 NWERC 2006
有 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的更多相关文章
- 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 ...
- LA 3635 Pie
题意:给出n个圆,分给n+1个人,求每个人最多能够得到多大面积的圆 二分每个人得到的圆的面积 #include<iostream> #include<cstdio> #incl ...
- 集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096)
集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096) 题目描述 有一个专门为了集合运算而设计的"集合栈"计算机.该 ...
- Java实现派(Pie, NWERC 2006, LA 3635)
题目 有F+1个人来分N个圆形派,每个人得到的必须是一整块派,而不是几块拼在一起,且面积要相同.求每个人最多能得到多大面积的派(不必是圆形). 输入的第一行为数据组数T.每组数据的第一行为两个整数N和 ...
- Uva 派 (Pie,NWERC 2006,LA 3635)
依然是一道二分查找 #include<iostream> #include<cstdio> #include<cmath> using namespace std; ...
- LA 3635 派
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 3635 Pie 切糕大师 二分
题意:为每个小伙伴切糕,要求每个小盆友(包括你自己)分得的pie一样大,但是每个人只能分得一份pie,不能拿两份凑一起的. 做法:二分查找切糕的大小,然后看看分出来的个数有没有大于小盆友们的个数,它又 ...
- UVa Live 3635 - Pie 贪心,较小的可能不用 难度: 2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVaLive 3635 Pie (二分)
题意:有f+1个人来分n个圆形派,每个人得到的必须是一个整块,并且是面积一样,问你面积是多少. 析:二分这个面积即可,小了就多余了,多了就不够分,很简单就能判断. 代码如下: #pragma comm ...
随机推荐
- 全注解的SSH框架
基于struts2.23 + spring2.5.6 + hibernate3.6.4 + hibernate-generic-dao1.0(除了spring,我整合的都是最新的GA包,hiberna ...
- 2016PHP开发者大会
大会干货: Rasmus Lerdorf——<Speeding up the Web with PHP 7> PHP 7 is here. It brings drastic perfor ...
- linux下对普通用户设置文件访问控命令之setfacl
命令名 setfacl -设置文件访问控制列表 常用用法:setfacl [-bkRd] [{-m|-x} acl参数] 目标文件名 命令的常用参数 -m 设置后续的acl参数给文件使用(常用). ...
- React事件属性
一.简介 二.滚动例子,滚动改变颜色 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta c ...
- QApplication::alert 如果窗口不是活动窗口,则会向窗口显示一个警告(非常好用,效果就和TeamViewer一样)
void QApplication::alert(QWidget * widget, int msec = 0)如果窗口不是活动窗口,则会向窗口显示一个警告.警报会显示msec 毫秒.如果毫秒为零,闪 ...
- nasm fasm yasm 还是masm、gas
留个爪,稍后学习 选择编译器nasm?fasm?yasm?还是masm.gas或其他? 前面三个是免费开源的汇编编译器,总体上来讲都使用Intel的语法.yasm是在nasm的基础上开发的,与nasm ...
- 307. Range Sum Query - Mutable
题目: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclu ...
- 利用Apriori算法对交通路况的研究
首先简单描述一下Apriori算法:Apriori算法分为频繁项集的产生和规则的产生. Apriori算法频繁项集的产生: 令ck为候选k-项集的集合,而Fk为频繁k-项集的集合. 1.首先通过单遍扫 ...
- [c/c++]指针数组 pk 数组指针
首先强调 指针数组归根结底是个数组:数组指针归根结底是个指针. 数组指针 以int (*int)[10]为例 ()的优先级大于[],因此首先它是一个指针,它指向一个数组,数组的维数是10.因此数组指针 ...
- ubuntu 12.10无法用apt-get安装软件 Err http://us.archive.ubuntu.com quantal-updates/main Sources 404 Not
之前执行apt-get 不管是什么软件或apt-get update都会遇到fail to fetch http://us.archive.ubuntu.com quantal-updates/ma ...