Cable master

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2473    Accepted Submission(s): 922

Problem 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 input 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.

 
Output
For each 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).

 
Sample Input
4 11 8.02 7.43 4.57 5.39 0 0
 
Sample Output
2.00
 题解:就是N根旧电缆,要求裁剪K分的最大长度;
hd过了的代码:但poj不过;;
 #include<stdio.h>
double m[];
int N;double sum,K;
double search(){int temp=;
double l=,r=sum/K,mid;
while(r-l>1e-){temp=;
mid=(l+r)/;
for(int i=;i<N;++i)temp+=(int)(m[i]/mid);//temp代表能裁剪成的数量。。。
if(temp>=K)l=mid;
else r=mid;
}
return mid;
}
int main(){
while(scanf("%d%lf",&N,&K),N||K){sum=;
for(int i=;i<N;++i)scanf("%lf",&m[i]),sum+=m[i];
printf("%.2lf\n",search());
}
return ;
}

poj ac:

 #include<stdio.h>
double m[];
int N;double sum,K;
double search(){int temp=;
double l=,r=sum/K,mid;
while(r-l>1e-){temp=;
mid=(l+r)/;
for(int i=;i<N;++i)temp+=(int)(m[i]/mid);
if(temp>=K)l=mid;
else r=mid;
}
return r;
}
int main(){double d;double t;
while(~scanf("%d%lf",&N,&K)){sum=;
for(int i=;i<N;++i)scanf("%lf",&m[i]),sum+=m[i];
d=search();
/// t=100*d;printf("%d\n",t);
printf("%.2f\n",(int)(d*)/100.0);
}
return ;
}

Cable master(好题,二分)的更多相关文章

  1. poj 1064 Cable master【浮点型二分查找】

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 29554   Accepted: 6247 Des ...

  2. Cable master poj1064(二分)

    http://poj.org/problem?id=1064 题意:共有n段绳子,要求总共被分为k段.问在符合题意的前提下,每段长最大是多少? #include <iostream> #i ...

  3. Cable master(二分题 注意精度)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26596   Accepted: 5673 Des ...

  4. POJ 1064 Cable master(二分查找+精度)(神坑题)

    POJ 1064 Cable master 一开始把 int C(double x) 里面写成了  int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...

  5. [ACM] poj 1064 Cable master (二分查找)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21071   Accepted: 4542 Des ...

  6. (poj)1064 Cable master 二分+精度

    题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...

  7. poj 1064 Cable master 判断一个解是否可行 浮点数二分

    poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...

  8. POJ 1064 Cable master (二分查找)

    题目链接 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. ...

  9. Cable master(二分-求可行解)

    Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Commi ...

随机推荐

  1. SqlDependency不起作用

    今天使用SqlDependency,结果不起作用,失效,不管数据库怎么修改,这边都没反应,OnChange事件总是不执行,很奇怪.我打开msdn里的例子,代码复制出来,结果没问题,能执行,那剩下来的问 ...

  2. C库函数笔记

    一.string.h 1.memcpy 函数原型:void *memcpy(void *dest, const void *src, size_t n); 功能:从源src所指的内存地址的起始位置开始 ...

  3. AfxBeginThread的介绍/基本用法

    AfxBeginThread    用户界面线程和工作者线程都是由AfxBeginThread创建的.现在,考察该函数:MFC提供了两个重载版的AfxBeginThread,一个用于用户界面线程,另一 ...

  4. 黑马程序员—— Java SE(2)

    ----<a href="http://www.itheima.com" target="blank">Java培训.Android培训.iOS培训 ...

  5. web跳转到自己的app

    做个笔记 原文:http://blog.csdn.net/ba_jie/article/details/6884818 iPhone SDK可以把你的App和一个自定义的URL Scheme绑定.该U ...

  6. 上拉、下拉UITableView,交互式 模态弹出(自定义弹出动画)

    部分代码 InteractiveTransition 类继承NSObject: - (instancetype)initWithPresentingController:(UITableViewCon ...

  7. winsocket <研究了一天的成果>

    首先,这都是套路( ▼-▼ ) 头文件     #include <WinSock.h> #include <Winsock2.h> 用这个,这个是升级版 各个函数解释 1.W ...

  8. (转)Should I use char** argv or char* argv[]

      As you are just learning C, i recommend you to really try to understand the differences between ar ...

  9. POJ2533:Longest Ordered Subsequence(LIS)

    Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence ...

  10. PHP基础示例:用PHP+Mysql编写简易新闻管理系统

    实现目标:使用php和mysql操作函数实现一个新闻信息的发布.浏览.修改和删除操作 实现步骤: 一.创建数据库和表 1.创建数据库和表:newsdb 2.创建表格:news 字段:新闻id,标题,关 ...