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 ...
随机推荐
- Coder的好伙伴Github
网络越来越发达,各式各样的网盘.云存储也走进日常生活, 在老师的指导下,我第一次接触了GitHub. 什么是Github? Github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一 ...
- idea导出war包
使用idea一个月了还没有用到导出war,今天突然需要我来部署测试war包,想使用myeclipse的,转念一想太掉价了 废话少说,直接上菜 如果你没有第一步操作我建议你配置一下你的idea 当然还有 ...
- Oracle 每隔5分钟产生2个clsc*.log文件
环境: OS:HP-UNIX 数据库:11.2.0.4 双机RAC (一)现象 在清理Oracle日志的时候,发现在$ORACLE_HOME/log/{instance_id}/client下面存 ...
- TCP/IP(一)之初识计算机网络
前言 在一段时间里,都很想知道一台电脑怎么跟另一台电脑通信的,我发送一个qq给女朋友,怎么准确的发送过去的,又是怎么接受消息的. 接下来一段时间给大家慢慢分享关于计算机网络的相关知识. 一.局域网.广 ...
- 【转】TCP/IP协议中TCP和UDP的区别
TCP协议与UDP协议的区别 首先咱们弄清楚,TCP协议和UCP协议与TCP/IP协议的联系,很多人犯糊涂了,一直都是说TCP/IP协议与UDP协议的区别,我觉得这是没有从本质上弄清楚网络通信! ...
- 使用javaAPI操作hdfs
欢迎到https://github.com/huabingood/everyDayLanguagePractise查看源码. 一.构建环境 在hadoop的安装包中的share目录中有hadoop所有 ...
- JavaWeb(四)EL表达式
前言 前面详细的说明了什么是JSP和它的一些元素,这篇给大家介绍一下的是EL表达式. 用EL表达式,能更好的使用JSP中的各种内置对象和作用域. 楼主作为大四狗马上要出去面试了,内心很紧张!!! 一. ...
- NSString与NSMutableString的浅拷贝与深拷贝
浅拷贝:指针拷贝,指针与原指针地址相同,没有创建新的对象. 深拷贝:内容拷贝,创建了新的对象,指针地址与原对象的指针地址不同. NSString测试代码如下 打印结果如下(后面打印出的两个NSCFCo ...
- Mysql安装后打开MySQL Command Line Client闪退解决方法
1.开始菜单下;Mysql--->mysql server 5.6-->mysql command line Client ---右击,选择属性 2.在属性下查看目标位置: 3.将安装目录 ...
- Kvm虚拟化的一种打包及部署方案(采用tar包,lvm方式)
Kvm虚拟化的一种打包部署方案(采用tar包,lvm方式) –-–-–-2016年终总结 一 毕业之后跟师兄学到的第一块主要内容,理解花了不少时间.期间经历了shell的入门.linux基础知识入门. ...