Problem 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 input
consists of several testcases. The first line of each testcase
contains two integer numbers 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 centimeter and at most 100 kilometers in length. All
lengths in the input are written with a centimeter precision, with
exactly two digits after a decimal point.



The input is ended by line containing two 0's.
Output
For each
testcase write to the output 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 must
contain the single number "0.00" (without quotes).
Sample Input
4 11
8.02
7.43
4.57
5.39
0 0
Sample Output
2.00
题意:给你n根绳子,分成k段,最多分多大;
解题思路:这个和分蛋糕的那个是一个思路,除了题目难看之外别的没什么难度;二分的范围是0到sum/k;
感悟:很久没有一气呵成的代码,一遍过了,真爽啊!!!
代码:
#include

#include

#include

#define maxn 10010

#define eps 1e-8

using namespace std;

double len[maxn];

int n,k;

bool judge(int n,int k,double mid)

{

    int
cnt=0;

    for(int
i=0;i

       
cnt+=(int)(len[i]/mid);

    return
cnt>=k;

}

int main()

{

   
//freopen("in.txt", "r", stdin);

   
while(~scanf("%d%d",&n,&k)&&(n||k))

    {

       
double s=0;

       
for(int i=0;i

       
{

           
scanf("%lf",&len[i]);

           
s+=len[i];

       
}

       
s/=k;//理论上分的最大的绳子

       
double left,right,mid;

       
left=0;right=s;

       
while(right-left>=eps)

       
{

           
mid=(left+right)/2;

           
if(judge(n,k,mid))

               
left=mid;

           
else

               
right=mid;

       
}

       
printf("%.2f\n",mid);

    }

}

Cable master的更多相关文章

  1. POJ 1064 Cable master (二分)

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

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

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

  3. Cable master(二分题 注意精度)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26596   Accepted: 5673 Des ...

  4. POJ 1064 Cable master

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37865   Accepted: 8051 Des ...

  5. Cable master

    Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...

  6. (poj)1064 Cable master 二分+精度

    题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...

  7. poj 1064 Cable master【浮点型二分查找】

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

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

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

  9. Cable master(好题,二分)

    Cable master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  10. [ACM] poj 1064 Cable master (二进制搜索)

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

随机推荐

  1. jsonp其实很简单【ajax跨域请求】

    js便签笔记(13)——jsonp其实很简单[ajax跨域请求] 前两天被问到ajax跨域如何解决,还真被问住了,光知道有个什么jsonp,迷迷糊糊的没有说上来.抱着有问题必须解决的态度,我看了许多资 ...

  2. 一个综合实例讲解vue的基础知识点。

    本文通过一个简单的实例来讲解一下vue的基本知识点.通过这个综合实例的讲解,vue的基础知识就会掌握的差不多了. 首先看一下项目的效果:

  3. "HK"日常之用C# Process写一只小病毒

    众所周知,Process可以启动和关闭电脑上的进程,命名空间位于 System.Diagnostics,本次的教程就是利用其中的GetProcesses和Kill方法来实现的. 一.编码工作 首先我们 ...

  4. Ubuntu16笔记本双显卡安装NVIDIA驱动

    blockquote { direction: ltr; color: rgb(0, 0, 0) } blockquote.western { font-family: "Liberatio ...

  5. Ubuntu 普通用户提升到root权限

    方法一.修改passwd文件 1.编辑passwd文件 sudo vim /etc/passwd 2.找到你想提权的用户(比如test),将用户名后面的数字改成0 找到用户test test:x::: ...

  6. Linux下安装jdk8的详细步骤

    一.登录Linux,切换到root用户 sudo su 二.在usr目录下建立java安装目录 cd /usr mkdir java 三.下载jdk 登录网址:http://www.oracle.co ...

  7. Python学习手册 :Python 学习笔记第一天

    获取当前目录路径: import os os.getcwd() 在输入python程序时,尽量让不是嵌套结构的语句处于最左侧,要不然系统或许会出现"SyntaxError"错误 获 ...

  8. ZOJ1181 Word Amalgamation 字符串 排序查找

    传送门:ZOJ1181  思路:自身排序来判断两个字符串拥有相同的字符.   #include<cstdio> #include<cstdlib> #include<io ...

  9. 不错的JQuery屏幕居中提示信息封装,使用方便,可集成到项目

    function showLoad(tipInfo, type, autohide) { var pic = ""; switch (type) { case 0: // load ...

  10. wpf 制作必输项的*标记

    直接引用帮助文档上的话吧,以免下次忘记! AdornedElementPlaceholder 类 .NET Framework 3.5   其他版本   此主题尚未评级 - 评价此主题   更新:20 ...