Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6639    Accepted Submission(s): 2514

Problem Description
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N of them, of various tastes and of various sizes. F of my friends are coming to my party and each of them gets a piece of pie. This should be one piece of one pie, not several small pieces since that looks messy. This piece can be one whole pie though.

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.

 
Input
One 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.
 
Output
For 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
 

同样是在一个限值范围中寻找最优值,然后在这个范围中进行二分优化,不过这道题要注意精度的概念,通常如果两个数相差不到10的-6次方,这两个数就可以认为是相等的了

限值是什么?当然是每个人应该得到多大的东西了,不过要注意k要加1,因为主人自己也要一份

#include"iostream"
#include"algorithm"
#include"cstring"
#include"cmath"
#include"cstdio"
#define mi 1e-6
using namespace std; const double pi=acos(-1.0);
const int maxn=+; int n,k;
double a[maxn];
double tot; void Init()
{
cin>>n>>k;
tot=;
k++;
for(int i=; i<n; i++)
{
cin>>a[i];
a[i]=pi*a[i]*a[i];
tot+=a[i];
}
} int need(double num)
{
int c=;
for(int i=; i<n; i++) c+=int(a[i]/num);
return c>=k?:;
} void guess()
{
double l,r,m;
l=;
r=tot/k;
while(r-l>mi)
{
m=l+(r-l)/;
if(need(m)) l=m;
else r=m;
}
printf("%6.4f\n",l);
} int main()
{
int T;
cin>>T;
while(T--)
{
Init();
guess();
}
return ;
}

集训第四周(高效算法设计)C题 (二分查找优化题)的更多相关文章

  1. 集训第四周(高效算法设计)N题 (二分查找优化题)

    原题:poj3061 题意:给你一个数s,再给出一个数组,要求你从中选出m个连续的数,m越小越好,且这m个数之和不小于s 这是一个二分查找优化题,那么区间是什么呢?当然是从1到数组长度了.比如数组长度 ...

  2. 集训第四周(高效算法设计)B题 (二分查找优化题)

    ---恢复内容开始--- Description   Before the invention of book-printing, it was very hard to make a copy of ...

  3. 数据结构和算法设计专题之---二分查找(Java版)

    1.前提:二分查找的前提是需要查找的数组必须是已排序的,我们这里的实现默认为升序 2.原理:将数组分为三部分,依次是中值(所谓的中值就是数组中间位置的那个值)前,中值,中值后:将要查找的值和数组的中值 ...

  4. 南理第八届校赛同步赛-F sequence//贪心算法&二分查找优化

    题目大意:求一个序列中不严格单调递增的子序列的最小数目(子序列之间没有交叉). 这题证明贪心法可行的时候,可以发现和求最长递减子序列的长度是同一个方法,只是思考的角度不同,具体证明并不是很清楚,这里就 ...

  5. js基本算法:冒泡排序,二分查找

    知识扩充: 时间复杂度:算法的时间复杂度是一个函数,描述了算法的运行时间.时间复杂度越低,效率越高. 自我理解:一个算法,运行了几次时间复杂度就为多少,如运行了n次,则时间复杂度为O(n). 1.冒泡 ...

  6. Java数据结构和算法总结-数组、二分查找

    前言:在平时开发中数组几乎是最基本也是最常用的数据类型,相比链表.二叉树等又简单很多,所以在学习数据和算法时用数组来作为一个起点再合适不过了.本篇博文的所有代码已上传 github ,对应工程的 ar ...

  7. 数据结构和算法:Python实现二分查找(Binary_search)

    在一个列表当中我们可以进行线性查找也可以进行二分查找,即通过不同的方法找到我们想要的数字,线性查找即按照数字从列表里一个一个从左向右查找,找到之后程序停下.而二分查找的效率往往会比线性查找更高. 一. ...

  8. C#LeetCode刷题-二分查找​​​​​​​

    二分查找篇 # 题名 刷题 通过率 难度 4 两个排序数组的中位数 C#LeetCode刷题之#4-两个排序数组的中位数(Median of Two Sorted Arrays)-该题未达最优解 30 ...

  9. Leedcode算法专题训练(二分查找)

    二分查找实现 非常详细的解释,简单但是细节很重要 https://www.cnblogs.com/kyoner/p/11080078.html 正常实现 Input : [1,2,3,4,5] key ...

随机推荐

  1. 使用gitee(码云)创建项目

    注册登录 https://gitee.com/ 也可以直接用oschina的帐号. 创建项目 点击"+"号,创建项目. 执行git命令 本机创建一个你的这个项目目录,init后不要 ...

  2. iOS 消除Xcode警告

    - undeclared selector #pragma clang diagnostic push #pragma clang diagnostic ignored"-Wundeclar ...

  3. MySQL 一对多查询,合并多的一方的信息

    select   c.name,  (select   group_concat(name) from student   s   where  s.class_id =c.id ) from  cl ...

  4. Zznu 1913: yifan and matrix (多路归并)

    题目链接: 1913: yifan and matrix 题目描述: 有一个n*n的矩阵,在每一行取出一个数,可以得到n个数的和,问前n小的和分别是多少? 解题思路: 对于两个数组a[n],b[n], ...

  5. bzoj1572 [Usaco2009 Open]工作安排Job【贪心 堆】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1572 尽管这一题没有看题解,但是耗时还是比本应耗费的时间要长,所以还是写一下,以提升经验 这 ...

  6. 备份字段(CATALOGUE_CODE)

    update am_e4_entry set CATALOGUE_CODE_back=CATALOGUE_CODE; 还原字段 update am_e4_entry a set CATALOGUE_C ...

  7. 转【Python】Python-skier游戏[摘自.与孩子一起学编程]

    http://www.cnblogs.com/zhaoxd07/p/4914818.html 我遇到的问题 问题1 self.image=pygame.image.load("skier_d ...

  8. [转]Oracle - 数据库的实例、表空间、用户、表之间关系

    本文转自:http://www.cnblogs.com/adforce/p/3312252.html 完整的Oracle数据库通常由两部分组成:Oracle数据库和数据库实例. 1) 数据库是一系列物 ...

  9. AJPFX关于Java Object类常用方法小总结

    java.lang.Object   java.lang包在使用的时候无需显示导入,编译时由编译器自动导入. Object类是类层次结构的根,Java中所有的类从根本上都继承自这个类. Object类 ...

  10. GIT配置及用法

    ssh配置 TortoiseGit配置 用法: 下面是我整理的常用 Git 命令清单.几个专用名词的译名如下. Workspace:工作区 Index / Stage:暂存区 Repository:仓 ...