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 ...
随机推荐
- Python NLP入门教程
本文简要介绍Python自然语言处理(NLP),使用Python的NLTK库.NLTK是Python的自然语言处理工具包,在NLP领域中,最常使用的一个Python库. 什么是NLP? 简单来说,自然 ...
- Ngnix技术研究系列1-通过应用场景看Nginx的反向代理
随着我们业务规模的不断增长,整个系统规模由两年前的几十台服务器,井喷到现在2个数据中心,接近400台服务器,上百个WebApi站点,上百个域名. 这么多的WebApi站点这么多的域名,管理和维护成本很 ...
- PIC32MZ 通过USB在线升级 -- USB HID bootloader
了解 bootloader 的实现, 请加QQ: 1273623966(验证填bootloader); 欢迎咨询或定制bootloader; 我的博客主页 www.cnblogs.com/geekyg ...
- 移动端效果之Swiper
写在前面 最近在做移动端方面运用到了饿了么的vue前端组件库,因为不想单纯用组件而使用它,故想深入了解一下实现原理.后续将会继续研究一下其他的组件实现原理,有兴趣的可以关注下. 代码在这里:戳我 1. ...
- linux备份文件脚本
#!/bin/sh #Author: Opal TODAY=`date +%Y%m%d` YESTERDAY=`date -d"-1 day" +%Y%m%d` mkdir -p ...
- Jquery cookie操作示例,写入cookie,读取cookie,删除cookie
<html> <head> <meta name="viewport" content="width=device-width" ...
- (图文实例)用VB.net操作SQLite数据库
转载请注明出处:HateMath归来(http://www.cnblogs.com/hatemath/) 环境: Visual Studio 社区版 64位 Windows 7系统 新建的解决方案基于 ...
- iOS10新特性之SiriKit
在6月14日凌晨的WWDC2016大会上,苹果提出iOS10是一次里程碑并且推出了十个新特性,大部分的特性是基于iPhone自身的原生应用的更新,具体的特性笔者不在这里再次叙述,请看客们移步WWDC2 ...
- 四种Sandcastle方法生成c#.net帮助类帮助文档
方法一 前端时间在网上收集和自己平时工作总结整理了<干货,比较全面的c#.net公共帮助类>,整理完成上传github之后我又想,既然是帮助类,总得有个帮助文档于是乎想到了Sandcast ...
- ASP.NET没有魔法——ASP.NET MVC是如何运行的?它的生命周期是什么?
前面的文章我们使用ASP.NET MVC创建了个博客应用,那么它是如何工作的呢?我们都知道ASP.NET的程序需要部署到IIS上才能够通过浏览器来访问,那么IIS与ASP.NET MVC程序之间又是如 ...