UVa Live 3635 - Pie 贪心,较小的可能不用 难度: 2
题目
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1636
题意
f+1个人分n个派,要求每个人得到面积相同(但形状可以不一样的)一块。求该最大面积。
思路
为了不像刘书思路,直接选取了当前最大的分块面积。
注意: 最终可能只吃其中的几个,较小的可能不用!
感想
1. 较小的可能不用,谢谢test case
2. 虽然简单,但是较小的可能不用!这个原则非常重要!
代码
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<double, int> MyPair;
const int MAXN = 1e4 + ;
const double PI = acos(-1.0);
double areas[MAXN];
int partNums[MAXN]; int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int T;
scanf("%d", &T);
for (int ti = ; ti <= T; ti++) {
int n, f;
scanf("%d%d", &n, &f);
f++;
double ans = 1e9;
for (int i = ; i < n; i++) {
int r;
scanf("%d", &r);
areas[i] = r * r * PI;
}
int num = ;
priority_queue<MyPair> que;
for (int i = ; i < n; i++) {
partNums[i] = ;
que.push(MyPair(areas[i], i));
}
while (num < f) {
ans = min(ans, que.top().first);
int ind = que.top().second;
que.pop();
partNums[ind]++;
num++;
que.push(MyPair(areas[ind] / (partNums[ind] + ), ind));
}
printf("%.4f\n", ans);
} return ;
}
UVa Live 3635 - Pie 贪心,较小的可能不用 难度: 2的更多相关文章
- uva 1615 高速公路(贪心,区间问题)
uva 1615 高速公路(贪心,区间问题) 给定平面上n个点和一个值D,要求在x轴上选出尽量少的点,使得对于给定的每个点,都有一个选出的点离它的欧几里得距离不超过D.(n<=1e5) 对于每个 ...
- 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 ...
- UVA 10718 Bit Mask 贪心+位运算
题意:给出一个数N,下限L上限U,在[L,U]里面找一个整数,使得N|M最大,且让M最小. 很明显用贪心,用位运算搞了半天,样例过了后还是WA,没考虑清楚... 然后网上翻到了一个人家位运算一句话解决 ...
- UVA - 11134 Fabled Rooks[贪心 问题分解]
UVA - 11134 Fabled Rooks We would like to place n rooks, 1 ≤ n ≤ 5000, on a n × n board subject to t ...
- UVA 10714 Ants 蚂蚁 贪心+模拟 水题
题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路 ...
- UVa 11729 - Commando War(贪心)
"Waiting for orders we held in the wood, word from the front never came By evening the sound of ...
- UVALive 3635 Pie 切糕大师 二分
题意:为每个小伙伴切糕,要求每个小盆友(包括你自己)分得的pie一样大,但是每个人只能分得一份pie,不能拿两份凑一起的. 做法:二分查找切糕的大小,然后看看分出来的个数有没有大于小盆友们的个数,它又 ...
- UVA 10020 Minimal coverage(贪心 + 区间覆盖问题)
Minimal coverage The Problem Given several segments of line (int the X axis) with coordinates [Li, ...
- UVA 11039-Building designing【贪心+绝对值排序】
UVA11039-Building designing Time limit: 3.000 seconds An architect wants to design a very high build ...
随机推荐
- 记录flask使用模板时出现的“Internal Server Error”错误
在看<Flask Web开发实战:入门.进阶与原理解析(李辉著 )>时照着书上的代码抄了一遍,然后运行时发现一直出现以下的错误 书上的源代码如下 watchlist.html <he ...
- 最大的矩形面积 Maximal Rectangle
2018-09-15 10:23:44 一.Largest Rectangle in Histogram 在求解最大的矩形面积之前,我们先讨论一条最大直方图面积的问题. 问题描述: 问题求解: 解法一 ...
- powerdesiger 导入sqlserver 方法
https://jingyan.baidu.com/album/7f766daf465e9c4101e1d0d5.html
- 验证码之SimpleCaptcha (一)
在captcha中,两个比较著名的框架验证码有Jcaptcha和simpleCaptcha,Jcaptcha太庞大了,所以我选择了简单的SimpleCaptcha simpleCaptch ...
- 20165327 2017-2018-2 《Java程序设计》第7周学习总结
20165327 2017-2018-2 <Java程序设计>第7周学习总结 教材内容总结 第十一章 (一)MySQL数据库服务器 下载安装MySQL服务器 启动MySQL数据库服务器 在 ...
- java --> Long和long/Integer和int
java中非一切是对象,因为还有基本数据类型. 基本数据类型有对应的基本数据类型打包器,它们的基本数据类型打包器是对象. j2se 5.0引入装箱和拆箱,它们是基本数据类型和基本数据类型打包器的关系 ...
- Mycat水平拆分之十种分片规则
水平切分分片实现 配置schema.xml 在同一个mysql数据库中,创建了三个数据库 testdb1,testdb2,testdb3.并在每个库中都创建了user表 <?xml ...
- LeetCode--682--棒球比赛(java)
你现在是棒球比赛记录员. 给定一个字符串列表,每个字符串可以是以下四种类型之一:1.整数(一轮的得分):直接表示您在本轮中获得的积分数.2. "+"(一轮的得分):表示本轮获得的得 ...
- codeforces590b//Chip 'n Dale Rescue Rangers//Codeforces Round #327 (Div. 1)
题意:从一点到另一点,前t秒的风向与t秒后风向不同,问到另一点的最短时间 挺难的,做不出来,又参考了别人的代码.先得到终点指向起点的向量,设T秒钟能到.如果T>t则受风1作用t秒,风2作用T-t ...
- 参考hadoop
参考hadoop http://blog.itpub.net/26613085/