poj1064 Cable master(hdoj1551)
2015-07-30 19:18
239 查看
Cable master
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 first line of the input file contains two integer numb ers 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 meter and at most 100 kilometers in length. All lengths in the input file are written with a centimeter precision, with exactly two
digits after a decimal point.
Output
Write to the output file 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 file must contain the single number "0.00" (without quotes).
Sample Input
Sample Output
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 29659 | Accepted: 6260 |
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 first line of the input file contains two integer numb ers 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 meter and at most 100 kilometers in length. All lengths in the input file are written with a centimeter precision, with exactly two
digits after a decimal point.
Output
Write to the output file 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 file must contain the single number "0.00" (without quotes).
Sample Input
4 11 8.02 7.43 4.57 5.39
Sample Output
2.00
嗯,题目大意就是说,切割电线的问题,n和k,共剩下n条线,但是需要同等长度的线k条,然后是n条线的长度,问切成的k条线最长为多少
哎,真心不会做二分的题啊,看了题都不知道怎么用二分,学长讲了之后才懂,自己再做其他的题还不一定会做,,,,
#include<cstdio> #include<cstring> double rec[10010]; int n,k; int f(double x) { int cnt=0; for(int i=0;i<n;++i) cnt+=(int)(rec[i]/x); if(cnt>=k) return 1; return 0; } int main() { double l,r,mid; while(~scanf("%d %d",&n,&k))//呃,输入格式改成while(scanf("%d %d",&n,&k)&&(n||k))杭电就过了,无语ing。。。。 { memset(rec,0,sizeof(rec)); for(int i=0;i<n;++i) scanf("%lf",&rec[i]); l=0; r=100000; while(r-l>1e-10) { mid=(r+l)/2; if(f(mid)) l=mid; else r=mid; } r=(int)(r*100)/100.0; printf("%.2f\n",r); } return 0; }
相关文章推荐
- HDU5335.Walk Out
- hdu 4280 Island Transport(最大流)
- JSTL中<fmt:bundle >找不到properties文件的原因
- 暴力求解——UVA 572(简单的dfs)
- hdu5336 十滴水游戏的模拟
- Material Design
- android省市区三级联动案例:(三)布局文件
- 求两个数的最大公约数和最小公倍数
- 对C标准中空白字符的理解(转)
- HDU 5336 XYZ and Drops
- Visual Studio Online 创建项目
- VS2010(64)+Qt4.8.0+PCL1.6.0+Vtk配置显示点云
- hdu5328 最长的连续的等比或等差数列
- Android内存泄漏分析及调试
- 【Java EE 学习 17 下】【数据库导出到Excel】【多条件查询方法】
- select用法详解 http://blog.chinaunix.net/uid-23373524-id-2426940.html
- SVN Cleanup failed to process the following paths
- HDOJ 1022 Train Problem I(栈)
- poj 3264 Balanced Lineup【RMQ-ST查询区间最大最小值之差 +模板应用】
- RSA ENCRYPT