Pie 杭电1969 二分
My friends are very annoying and if one of them gets a bigger piece than the others, they start complaining. Therefore all of them should get equally sized (but not necessarily equally shaped) pieces, even if this leads to some pie getting spoiled (which is better than spoiling the party). Of course, I want a piece of pie for myself too, and that piece should also be of the same size.
What is the largest possible piece size all of us can get? All the pies are cylindrical in shape and they all have the same height 1, but the radii of the pies can be different.
InputOne line with a positive integer: the number of test cases. Then for each test case:
---One line with two integers N and F with 1 <= N, F <= 10 000: the number of pies and the number of friends.
---One line with N integers ri with 1 <= ri <= 10 000: the radii of the pies.
OutputFor each test case, output one line with the largest possible volume V such that me and my friends can all get a pie piece of size V. The answer should be given as a floating point number with an absolute error of at most 10^(-3).Sample Input
3
3 3
4 3 3
1 24
5
10 5
1 4 2 3 4 5 6 5 4 2
Sample Output
25.1327
3.1416
50.2655 思路 : 刚看到题目时以为是贪心 然后把我给写自闭了,,这个题目要用二分法来做,,找两个极值,,一个是极小值或者最小的蛋糕/m 极大值就是最大的蛋糕啦! 接下来就是判断 就是让每一块蛋糕的面积/mid 利用保留正数字的原则,就是判断当个人分mid面积是,,每一块蛋糕可以提供几个人的量.
AC代码:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#define N 10010
#define M_PI 3.1415926535898
using namespace std;
double arr[N];
int n,m; int judge(double x){
int cnt=;
for(int i=;i<n;i++){
cnt+=arr[i]/x;
}
if(cnt>=m) return ;
return ;
} int main()
{
int t;
cin>>t;
while(t--){
cin>>n>>m;
m++;
int r;
double sum=;
for(int i=;i<n;i++){
cin>>r;
arr[i]=M_PI*r*r;//保存每个蛋糕的面积
} double low,high;
sort(arr,arr+n); low=arr[]/m;//最小取值
high=arr[n-];//最大取值 double mid=(high+low)/; while(fabs(high-low)>1e-)
{
mid=(high+low)/; if(judge(mid))
{
low=mid;
} else {
high=mid;
}
}
printf("%.4lf\n",mid);
}
return ;
}
Pie 杭电1969 二分的更多相关文章
- Pie(hdu 1969 二分查找)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 杭电dp题集,附链接还有解题报告!!!!!
Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱 最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...
- 杭电ACM题单
杭电acm题目分类版本1 1002 简单的大数 1003 DP经典问题,最大连续子段和 1004 简单题 1005 找规律(循环点) 1006 感觉有点BT的题,我到现在还没过 1007 经典问题,最 ...
- 2017杭电ACM集训队单人排位赛 - 6
2017杭电ACM集训队单人排位赛 - 6 排名 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 59 1 X X 1 1 X X 0 1 ...
- acm入门 杭电1001题 有关溢出的考虑
最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...
- 杭电acm 1002 大数模板(一)
从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...
- 杭电OJ——1198 Farm Irrigation (并查集)
畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...
- 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...
随机推荐
- 洛谷3388 tarjan割点
题目链接:https://www.luogu.com.cn/problem/P3388 tarjan算法果然牛逼,时间复杂度是O(|V|+|E|),所以1e4个结点2e5条边的图完全不在话下orz o ...
- Python中保留两位小数的几种方法
https://blog.csdn.net/Jerry_1126/article/details/85009810 保留两位小数,并做四舍五入处理方法一: 使用字符串格式化>>> a ...
- MATLAB中mean的用法
https://blog.csdn.net/wangyang20170901/article/details/78745587 MATLAB中mean的用法 转载仙女阳 最后发布于2017-12-07 ...
- 热点 | 四月最佳Github项目库与最有趣Reddit热点讨论
来源:Analytics Vidhya 编译:磐石 [磐创AI导读]:Github是全球最大的开源代码社区,Reddit是最受大家欢迎的热点讨论交流平台.接下来磐创AI将为大家带来四月份Github最 ...
- java 环境变量配置与第一个程序运行
从开始下载jdk,到运行出java第一个程序 ,花了5天时间 ,不过我相信万事开头难 ,以后会越来越好的 ,加油! jdk的下载: 在oracle官网上即可下载,jdk安装包,下载完以后运行安装 ,路 ...
- hive的基本操作与应用
通过hadoop上的hive完成WordCount 启动hadoop Hdfs上创建文件夹 创建文件夹 上传文件至hdfs 启动Hive 创建原始文档表 导入文件内容到表docs并查看 用HQL进行词 ...
- Python批量修改文件名模板
源码如下:import os import re import sys filePath = r'F:\BaiduNetdiskDownload\COVID-19CTSeg\3DUNet-Pytorc ...
- HIT软件构造课程3.2总结(Designing Specificaton)
本节转向“方法/函数/操作”如何定义 上一节是名词 这一节是动词 1.编程语言中的函数和方法 方法 使用者不需要知道方法内部如何实现,这叫做“抽象”. 参数 参数类型是否匹配,在静态检查时完成. 返回 ...
- Python学习-第四节:常用模块-logging,re,time
1:logging模块 import logging logging.debug('This is debug message') logging.info('This is info message ...
- stm32:实现呼吸灯
1.main.c #include "sys.h" #include "delay.h" #include "key.h" #define ...