Cable master
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 29554   Accepted: 6247

Description

Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to connect computers for the contestants using a "star" topology - i.e. connect them all to a single central hub. To organize a truly honest contest, the Head of the Judging Committee has decreed to place all contestants evenly around the hub on an equal distance from it. 
To buy network cables, the Judging Committee has contacted a local network solutions provider with a request to sell for them a specified number of cables with equal lengths. The Judging Committee wants the cables to be as long as possible to sit contestants as far from each other as possible. 
The Cable Master of the company was assigned to the task. He knows the length of each cable in the stock up to a centimeter,and he can cut them with a centimeter precision being told the length of the pieces he must cut. However, this time, the length is not known and the Cable Master is completely puzzled. 
You are to help the Cable Master, by writing a program that will determine the maximal possible length of a cable piece that can be cut from the cables in the stock, to get the specified number of pieces.

Input

The first line of the input file contains two integer numb ers N and K, separated by a space. N (1 = N = 10000) is the number of cables in the stock, and K (1 = K = 10000) is the number of requested pieces. The first line is followed by N lines with one number per line, that specify the length of each cable in the stock in meters. All cables are at least 1 meter and at most 100 kilometers in length. All lengths in the input file are written with a centimeter precision, with exactly two digits after a decimal point.

Output

Write to the output file the maximal length (in meters) of the pieces that Cable Master may cut from the cables in the stock to get the requested number of pieces. The number must be written with a centimeter precision, with exactly two digits after a decimal point. 
If it is not possible to cut the requested number of pieces each one being at least one centimeter long, then the output file must contain the single number "0.00" (without quotes).

Sample Input

4 11
8.02
7.43
4.57
5.39

Sample Output

2.00
1、最后的r输出是要用%f
2、刚开始一直错,看了别人的题解,发现原来并不一定要把所有的电缆都用上如数据
2 2
1.02
2.33
答案为1.16
3、还有就是要注意最后的结果并不是四舍五入,而是直接取小数点后两位
#include<stdio.h>
#include<string.h>
#define MAX 10100
#define maxn(x,y)(x>y?x:y)
double a[MAX];
int n,m;
int num(double x)//计算在x长度时最多可以有多少段这样做
{ //就解决了不一定全部电缆都要用的问题
int i,sum=0;
for(i=1;i<=n;i++)
{
sum+=(int)(a[i]/x);
}
return sum;
}
int main()
{
int i;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(a,0,sizeof(a));
double max=0,suma=0;
for(i=1;i<=n;i++)
{
scanf("%lf",&a[i]);
max=maxn(max,a[i]);
suma+=a[i];
}
if(suma/m<0.01)
printf("0.00\n");
else
{
double l=0.01,r=max,mid=0;
while(r - l >1e-8)
{
mid=(l+r)/2.0;
if(num(mid)>=m)
l=mid;
else
r=mid;
}
int tem=r*100;
double ans=tem*0.01;
printf("%.2f\n",ans);
}
}
return 0;
}

  

poj 1064 Cable master【浮点型二分查找】的更多相关文章

  1. POJ 1064 Cable master(二分查找+精度)(神坑题)

    POJ 1064 Cable master 一开始把 int C(double x) 里面写成了  int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...

  2. [ACM] poj 1064 Cable master (二分查找)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21071   Accepted: 4542 Des ...

  3. POJ 1064 Cable master (二分查找)

    题目链接 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. ...

  4. POJ 1064 Cable master (二分)

    题目链接: 传送门 Cable master Time Limit: 1000MS     Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...

  5. POJ 1064 Cable master 浮点数二分

    http://poj.org/problem?id=1064 题目大意: 有N条绳子,他们的长度分别为Li,如果从它们中切割出k条长度相同的绳子的话,这K条绳子每条能有多长? 思路: 二分,设答案为m ...

  6. POJ 1064 Cable master(二分答案)

    嗯... 题目链接:http://poj.org/problem?id=1064 其实这是一道很好想的二分答案的一道题... 二分的区间就是1~max_l,从1开始是因为所有小于1的都需要按0计算,没 ...

  7. poj 1064 Cable master ,二分 精度!!!

    给出n根绳子,求把它们分割成K条等长的绳子的最大长度是多少? 二分 用 for(int i=0; i<100; ++i) 取代   while(r-l>eps) 循环100次精度能达到1e ...

  8. POJ 1064 Cable master (二分答案,G++不过,C++就过了)

    题目: 这题有点坑,G++过不了,C++能过. 条件:n个数据a[],分成k段,结果精度要求两位小数. 问题:每段最长为多少? 思路:因为精度要求为两位小数,我先把所有的长度a[]*100. 我们对答 ...

  9. POJ 1064 Cable master 【二分答案】

    和杭电那一题一样,只不过G++交不能通过,C++能过 wa了好多好多好多次----------------------------------------- #include<iostream& ...

  10. poj 1064 Cable master 判断一个解是否可行 浮点数二分

    poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...

随机推荐

  1. Python:模块引用

    #!/usr/bin/python3 #Filename function.py #导入模块 import sys #导入function.py#function.py 文件import functi ...

  2. iterator迭代器的使用

    部分摘自C++ Primer: 所有的标准库容器类都定义了相应的iterator类型,如vector:vector<int>::iterator iter; 这条语句定义了一个名为iter ...

  3. jQuery仿苏宁易购导航

    最近看了些网上的各类导航网站源码,自己学习制作了一个仿苏宁易购的导航栏 jQuery部分代码 $(function(){ $(".CategoryTree>ul>li" ...

  4. 分享一个自己写的基于TP的关系模型(2)

    1.增加多对多关系的处理 /** * 定义关系 * @return array */ public function test4(){ //参数说明 //关联的模型 //主表关联字段 //关联中间表 ...

  5. nau8822 codec driver 录音时mic bias 无法自动打开问题

    nau8822 codec driver 录音时mic bias 无法自动打开问题 问题描述: kernel版本:3.10 在nuc970上测试nau8822驱动时发现,虽然驱动中有如下定义: SND ...

  6. jQuery.ajax() datatype:“json" 转换失败

    当使用jQuery.ajax() 时,如果设置dataType:"json",如果返回的字符转换出错则不会调用success方法,而进入error方法,控制台中也不会出现错误信息 ...

  7. CSS鼠标点击式变化图片透明度

    今天分享前端代码主题:jequery控制css图片透明度 很多时候在网站图片处理上需要实现一些辅助效果,比如鼠标在图片上滑动时或点击时改变图片颜色(变灰或者其他),其实一个简单的办法就是改变图片css ...

  8. 我学C的那些年[ch02]:宏,结构体,typedef

    c语言的编译过程: 预处理 编译 汇编 链接 而预处理中有三种情况: 文件包含( #include ) 条件编译(#if,#ifndef,#endif) 宏定义( #define ) 宏就是预处理中的 ...

  9. 应用git(SSH设置)

    git配置完成email和user后,才可以生成SSH Key. $ git config --global user.name "自定义名称" $ git config --gl ...

  10. [MVC] WebSecurity在VS2013中不识别

    使用VS2013创建了MVC4项目以后,在filters中添加了类InitializeSimpleMembershipAttribute ,不能识别UserContext和WebSecurity,发现 ...