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

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

给出n条绳子的长度,从这些绳子中切割出k条绳子,求能切割出的最大长度,保留两位小数。   设C(X)表示能否切割出长度为x的K条绳子。 二分枚举X就行了。
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
using namespace std;
const int INF=0x4fffffff;
const int EXP=1e-;
const int MS=; int N,K;
double len[MS]; bool judge(double x)
{
int cnt=;
for(int i=;i<=N;i++)
cnt+=(int)(len[i]/x+EXP);
return cnt>=K;
} void solve()
{
double l=0.0,r=MS*10.0;
double mid;
for(int i=;i<;i++)
{
mid=(l+r)/;
if(judge(mid))
l=mid;
else
r=mid; // 注意这里是double。
}
printf("%.2lf\n",floor(mid*)/);
// 千万注意精度
// printf("%.2lf\n",mid); WA
} int main()
{
scanf("%d%d",&N,&K);
for(int i=;i<=N;i++)
scanf("%lf",&len[i]);
solve();
return ;
}
												

Cable master(二分题 注意精度)的更多相关文章

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

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

  2. poj1064 Cable master(二分)

    Cable master 求电缆的最大长度(二分法)   Description Inhabitants of the Wonderland have decided to hold a region ...

  3. POJ 1064 Cable master | 二分+精度

    题目: 给n个长度为l[i](浮点数)的绳子,要分成k份相同长度的 问最多多长 题解: 二分长度,控制循环次数来控制精度,输出也要控制精度<wa了好多次> #include<cstd ...

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

    题目链接:http://poj.org/problem?id=1064 有n条绳子,长度分别是Li.问你要是从中切出m条长度相同的绳子,问你这m条绳子每条最长是多少. 二分答案,尤其注意精度问题.我觉 ...

  5. POJ 1064 Cable master (二分)

    题意:给定 n 条绳子,它们的长度分别为 ai,现在要从这些绳子中切出 m 条长度相同的绳子,求最长是多少. 析:其中就是一个二分的水题,但是有一个坑,那么就是最后输出不能四舍五入,只能向下取整. 代 ...

  6. poj 1064 Cable master 二分 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=1064 题解 二分即可 其实 对于输入与精度计算不是很在行 老是被卡精度 后来学习了一个函数 floor 向负无穷取整 才能ac 代码如下 ...

  7. [POJ] 1064 Cable master (二分查找)

    题目地址:http://poj.org/problem?id=1064 有N条绳子,它们的长度分别为Ai,如果从它们中切割出K条长度相同的绳子,这K条绳子每条最长能有多长. 二分绳子长度,然后验证即可 ...

  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 ...

随机推荐

  1. List小结

    假设有两个List集合,找出集合中重复的部分: //检测listX和listY中的重复部分 //把X复制到Z避免循环同时操作X从而出现异常              itemX.ForEach(i = ...

  2. HDU 1712 ACboy needs your help (分组背包模版题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...

  3. HDU 5164Matching on Array(AC自动机)

    这是BC上的一道题,当时比赛没有做,回头看看题解,说是AC自动机,想着没有写过AC自动机,于是便试着抄抄白书的模板,硬是搞了我数个小时2000ms时限1800过了= = ! 这里就直接贴上BC的结题报 ...

  4. LA4329 Ping pong(树状数组与组合原理)

    N (3N20000)ping pong players live along a west-east street(consider the street as a line segment). E ...

  5. C#.NET 消息机制

    一.消息概述 众人周知,window系统是一个消息驱动的系统, windows操作系统本身有自己的消息队列,消息循环,它捕捉键盘,鼠标的动作生成消息,并将这个消息传给应用程序的消息队列. 余下的工作有 ...

  6. hdoj 5344 MZL's xor

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5344 #include<stdio.h> #include<cstring> ...

  7. Activity之间使用intent传递大量数据带来问题总结

    转载:大飞 http://blog.csdn.net/rflyee/article/details/47441405   Activity之间使用Parcel传递大量数据产生的问题. Activity ...

  8. user is not in the sudoers file.This incident will be reported

    我用普通用户ssk登陆,想让ssk成为拥有超级用户的权限的普通用户 开始提示输入密码错误 ,然后就这样了   解决方法如下: 1>.进入超级用户模式.也就是输入"su -", ...

  9. 学习JQuery中文文档之map()函数和get()函数

    今天学到一个新的函数map(). map(callback) 官方概述: 将一组元素转换成其他数组(不论是否是元素数组) 你可以用这个函数来建立一个列表,不论是值.属性还是CSS样式,或者其他特别形式 ...

  10. (1) css的核心基础

     css的核心基础 1.css的基本语法在具体使用css之前,请各位兄弟姐妹先思考一个生活中的问题,一般情况下我们是如何描述一个人的呢? 小明{ 民族:汉族: 性格:温柔: 性别:男: 体重:68kg ...