题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1969

题意:看了老半天,就是有N个饼,要分给f+1个人,每个人只能一样多,不能拼凑,多余的丢弃,问每个人最多能分到多少

题解:将最大的那个饼拿来二分,然后无限逼近满足能分出f+1个相同大小的饼 ,的最大的答案。

关于二分查找的总结,这里可以看LightGHLi 的这篇文章,写的很不错 :二分查找总结

 #include<cstdio>
#include<cmath>
const double pi=acos(-1.0),eps=1e-;
int i,j,t,f,n,sum;
double a[],l,r,max,mid;
bool cs(double x){
for(j=,sum=;j<=n;j++)sum+=int(a[j]/x);
if(sum>=f+)return ;
return ;
}
int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&f);
for(i=,max=;i<=n;i++){scanf("%lf",&a[i]);a[i]=a[i]*a[i]*pi,max=max>a[i]?max:a[i];}
for(l=,r=max;l+eps<r;)if(cs(mid=(l+r)/2.0))l=mid;else r=mid;
printf("%.4lf\n",l);
}
return ;
}

hdu_1969_pie(二分)的更多相关文章

  1. BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]

    1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submi ...

  2. BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]

    2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 3352  Solved: 919[Submit][Stat ...

  3. 整体二分QAQ

    POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...

  4. [bzoj2653][middle] (二分 + 主席树)

    Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...

  5. [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

  6. [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值

    Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...

  7. jvascript 顺序查找和二分查找法

    第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...

  8. BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流

    1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...

  9. BZOJ 3110 [Zjoi2013]K大数查询 ——整体二分

    [题目分析] 整体二分显而易见. 自己YY了一下用树状数组区间修改,区间查询的操作. 又因为一个字母调了一下午. 貌似树状数组并不需要清空,可以用一个指针来维护,可以少一个log 懒得写了. [代码] ...

随机推荐

  1. MyEclipse中用Maven创建Web项目

    方法/步骤     new --> other   1.Wizards: mvaen 2.Maven Project 3.Next   Use Default Workspace Locatio ...

  2. libev实现分析

    libev是一个事件驱动库,底层是基于select.epoll.kqueue等I/O复用接口.所谓事件驱动库,就是用户定义一个事件以及改事件发生时调用的函数,该库会监听该事件,并在事件发生时调用相应的 ...

  3. java中多态的使用

    一.动手动脑 public class ParentChildTest { public static void main(String[] args) { Parent parent=new Par ...

  4. Idea1.5使用Maven搭建Apache Spark1.6源码阅读环境

    1.插件安装,在Idea界面依次:File->settings->plugins,安装Maven 2.下载Spark1.6.2源码,这个在GitHub上下载,具体流程自己百度,很简单 3. ...

  5. hexo常用命令笔记

    hexo npm install -g hexo npm update -g hexo hexo init 常用 hexo n == hexo new "a new post" 新 ...

  6. hitTest和pointInside和CGRectContainsPoint

    很多app中TabBar中间会有个凸起超出部分,为了点击超出父视图但是还想让按钮响应 //重写hitTest方法,去监听发布按钮的点击,目的是为了让凸出的部分点击也有反应- (UIView *)hit ...

  7. ListView的条目点击焦点的问题

    由于ListView条目里有ImageButton,导致抢占了条目点击事件,所以在item的跟布局中加入 android:descendantFocusability="blocksDesc ...

  8. C#Stopwatch的使用,性能测试

    一,先开启开始或继续测量某个时间间隔的运行时间,然后停止,最后重置时间,输出. using System; using System.Collections.Generic; using System ...

  9. js常见的判断移动端或者pc端或者安卓和苹果浏览器的方法总结

    1.js常见的判断移动端或者pc端或者安卓和苹果浏览器的方法总结 : http://www.haorooms.com/post/js_pc_iosandmobile 2.Js判断客户端是否为PC还是手 ...

  10. apt-get dpkg lock 和 debconf 问题

    一: 在用sudo apt-get install 安装软件时,由于速度太慢,想换个软件源,直接关闭了终端,apt-get但进程没有结束,结果终端提示 E: Could not get lock /v ...