Cable master 二分
来源:互联网 发布:notepad mac 破解 编辑:程序博客网 时间:2024/06/13 10:46
Cable master
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 23362 Accepted: 4995
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.
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).
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 118.027.434.575.39题目就是二分去写,C++ 要用 printf("%lf"); 在g++ 中,不知道为什么 直接写 int cnt=0;cnt = cnt +(int)(a[i]/x); 这样写往往会出错,暂且我还是不知道为什么,可能double存储有误差吧……
#include<stdio.h>#include<string.h>#include<math.h>#include<string>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<list>#include<map>#include<set>using namespace std;const int N = 10010 ;int n,K;double a[N];bool OK(double x){ int cnt = 0 ; for( int i = 0 ; i < n ; i++){ double tp = a[i] / x ; cnt = cnt + (int)tp; } if( cnt >= K ) return 1; return 0;}void work(){ double st=0,ed=1000000,mid; for( int i = 0 ; i < 100 ; i++){ mid = ( st + ed ) / 2; if( OK(mid) ) st = mid; else ed = mid ; } double ans = ed * 100 ; printf("%.2f\n",(int)ans/100.0);}int main(){//freopen("in.in","r",stdin);while(~scanf("%d%d",&n,&K)){ for(int i = 0 ; i < n ; i++ ){ scanf("%lf",&a[i]); } work();}return 0;}
0 0
- HDU1551:Cable master(二分)
- Cable master 二分
- POJ1064 Cable master(二分)
- POJ1064 Cable master 二分
- POJ1064 Cable master 二分
- POJ1064 Cable master(二分)
- HDU1551:Cable master(二分)
- HDU1551 Cable master(二分)
- POJ1064 Cable master(二分)
- Cable master 小数二分
- HDU1551:Cable master(二分)
- HDU1551:Cable master(二分)
- HDU1551:Cable master(二分)
- poj1064 Cable master(二分)
- POJ1064 Cable master[二分]
- Cable master(二分)
- Cable master (二分搜索)
- Cable Master(二分)
- TaskStackBuilder and extras for the back stack
- POJ 2886 Who Gets the Most Candies? (线段树)
- hdu 4908 BestCoder Sequence
- android-改进<<仿QQ>>框架源码
- 一些有用的sql语句整理
- Cable master 二分
- 周一,阴天。
- 循环比赛日程表
- 用jsp实现简单的图片上传功能
- 通过java类文件识别JDK编译版本
- 初识saltstack在之CentOS6上安装Saltstack
- 原型模式
- HDU 1069 Monkey and Banana
- 只有在配置文件或 Page 指令中将 enableSessionState 设置为 true 时,才能使用会话状态。还请确保在应用程序配置的 // 节中包括 System.Web.SessionSta