Cable master
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.
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.
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).
#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的更多相关文章
- POJ 1064 Cable master (二分)
题目链接: 传送门 Cable master Time Limit: 1000MS Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...
- [ACM] poj 1064 Cable master (二分查找)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21071 Accepted: 4542 Des ...
- Cable master(二分题 注意精度)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26596 Accepted: 5673 Des ...
- POJ 1064 Cable master
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37865 Accepted: 8051 Des ...
- Cable master
Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...
- (poj)1064 Cable master 二分+精度
题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...
- poj 1064 Cable master【浮点型二分查找】
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29554 Accepted: 6247 Des ...
- POJ 1064 Cable master(二分查找+精度)(神坑题)
POJ 1064 Cable master 一开始把 int C(double x) 里面写成了 int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...
- Cable master(好题,二分)
Cable master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- [ACM] poj 1064 Cable master (二进制搜索)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21071 Accepted: 4542 Des ...
随机推荐
- Linux Ubuntu从零开始部署web环境及项目 -----tomcat+jdk+mysql (二)
上一篇介绍如何在linux系统下搭建ssh环境 这篇开始将如何搭建web服务器 1,下载文件 在官网下载好 tomcat.jdk.mysql的linux压缩包 后缀名为.tar.gz 并通过xftp上 ...
- Coder的好伙伴Github
网络越来越发达,各式各样的网盘.云存储也走进日常生活, 在老师的指导下,我第一次接触了GitHub. 什么是Github? Github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一 ...
- ACM学习之路___HDU 1385(带路径保存的 Floyd)
Description These are N cities in Spring country. Between each pair of cities there may be one trans ...
- 用vue开发一个app(3,三天的成果)
前言 一个vue的demo 源码说明 项目目录说明 . |-- config // 项目开发环境配置 | |-- index.js // 项目打包部署配置 |-- src // 源码目录 | |-- ...
- [LeetCode] 231 Power of Two && 326 Power of Three && 342 Power of Four
这三道题目都是一个意思,就是判断一个数是否为2/3/4的幂,这几道题里面有通用的方法,也有各自的方法,我会分别讨论讨论. 原题地址:231 Power of Two:https://leetcode. ...
- 记录一次无聊的(经历了Nodejs -> Shell -> C)的探索问题过程
提出问题 在运行项目的服务器的git是1.8.3.1版本的时候,pm2 deploy 项目,服务器fetch不到最新的一次commit. 对于这个问题,在pm2的github也有issues讨论.然后 ...
- String的replace和replaceAll
replace(CharSequence target, CharSequence replacement) 这里CharSequence是一个接口 实现类包括CharBuffer, Segement ...
- swift 开发学习问题
1 UITableViewController 问题: [UITableView dequeueReusableCellWithIdentifier:forIndexPath:], unable to ...
- EOutOfResources字符异常
近日,用Delphi编程时,遇到一个莫名其妙的异常:EOutOfResources,这是一个可以重复再现的异常.开始以为是程序中创建的对象太多,导致占用了过多的资源,引起了这个异常.于是在代码中将许多 ...
- C# 中函数内定义函数的委托方法
//定义委托方法Action(无返回值)Func(有返回值) //无返回值委托 Action<string> SetKeyAndValue = delegate(string key) { ...