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 ...
随机推荐
- 简洁灵活的前端框架------BootStrap
前 言 Bootstrap,来自 Twitter,是目前很受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷.[1] ...
- C#进阶之AOP
一.AOP概念(转自) AOP(Aspect-Oriented Programming,面向切面的编程),它是可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技 ...
- Monit : 开源监控工具介绍
· Monit 简介 Monit是一个轻量级(500KB)跨平台的用来监控Unix/linux系统的开源工具.部署简单,并且不依赖任何第三方程序.插件或者库. Monit可以监控服务器进程.文件.文件 ...
- 简单Elixir游戏服设计-玩法simple_poker
上回介绍了玩法,现在编写了玩法的简单建模. 做到现在感觉目前还没有使用umbrella的必要(也许以后会发现必要吧),model 应用完全可以合并到game_server. 代码还在https://g ...
- Maven-环境搭建以及建立Maven项目
Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. 多的不说,直接开始这章节的主要内容. 1.maven下载地址http://maven.apac ...
- PHP-FPM进程池探秘
PHP 支持多进程而不支持多线程:PHP-FPM 在进程池中运行多个子进程并发处理所有连接请求.通过 ps 查看PHP-FPM进程池(pm.start_servers = 2)状态如下: root@d ...
- SAP GB01替代 程序:RGUGBR00
TCODE: SM30 VIEW : VWTYGB01 GB01 更新后需要执行 RGUGBR00
- web自动化测试从入门到持续集成(selenium webdriver)
在很多刚学习自动化的可能会认为我只需要会运用selenium,我只需要在一个编辑器中实用selenium +java编写了一些脚本那么就会自动化了,是真的吗?答案肯定是假的.自动化肯定是需要做到真的完 ...
- IIS ApplicationPoolIdentity(配置IIS讀寫網站文件)
原创地址:http://www.cnblogs.com/jfzhu/p/4067297.html 转载请注明出处 从IIS 7.5开始,Application Pool Identity的Built- ...
- Linux 可运行进程 Runnable Process Definition
From : http://www.linfo.org/runnable_process.html 一个可运行的进程是指该进程的进程状态为TASK_RUNNING. 进程,也可被称为任务,是指一个程序 ...