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. 第三百四十二天 how can I 坚持

    再问世间都去哪儿了,天气预报没搞完,计划没制定,又周三了. 今天回到家八点,吃完饭接近九点,和老妈开了会视频,这就九点半多了,发了呆洗了个碗就到这时候了,整天浑浑噩噩的,该如何是好. 又有点上火,舌头 ...

  2. SpringBoard

    [SpringBoard] Springboard, or Home Screen, is the standard application that manages the iOS home scr ...

  3. POJ 1696 Space Ant(极角排序)

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2489   Accepted: 1567 Descrip ...

  4. 动态生成xml文件

    使用xmlParser动态生成xml,输入的字符编码是gbk,结果怎么生成都不行,后来把输入转成utf8之后, 再生成就ok了

  5. UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  6. windows服务安装及卸载

    1)安装脚本Install.bat%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe JobSchedule.exeNet ...

  7. 求C#开发大神指点职业规划或者开发路数(以后怎么走),谢谢

    背景:作为一名Asp.net Web类的开发人员,工作时间有点长,5年不到,属于是天赋不太强,但是比较努力型的人,开发过程中那事情基本上都会,各种前后端框架也会使用.目前在研究分布式缓存应用 Memc ...

  8. 观察者模式:关于通知的使用(NSNotificationCenter)

    一.通知的使用方法 1.发出通知 例如:[[NSNotificationCenter defaultCenter]postNotificationName:@"backToFirstPage ...

  9. linux中less命令使用

    less与cat和more的区别: cat命令功能用于显示整个文件的内容单独使用没有翻页功能因此经常和more命令搭配使用,cat命令还有就是将数个文件合并成一个文件的功能. more命令功能:让画面 ...

  10. Toast在关闭应用后还显示的解决办法

    1.我们在用Toast的用法就是:Toast.makeText(Context,CharSequence , Duration).show().但有的时候如果你在一次操作当中多次点击一个view的时候 ...