二分-A - Cable master
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.
InputThe 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.
OutputFor 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 Input4 11
8.02
7.43
4.57
5.39
0 0Sample Output
2.00
#include<iostream>
using namespace std; double a[];
int n,k;
int solve(double x){//用于判断按照长度x分割,能不能得到大于等于需求量k
int sum=;
for(int i=;i<n;i++)
sum += a[i]/x;
if(sum >= k) return ;
else return ;
} int main(){
double right = 0.0;
while(~scanf("%d %d", &n, &k) && n && k){
for(int i=; i<n; i++){
scanf("%lf", &a[i]);
if(a[i]>right) right = a[i];//找到长度最大量最为二分的右值
}
double mid, left=a[]/k;
while(right-left > 1e-){
mid = (right + left)/;
if(solve(mid)) left = mid;
else right = mid;
}
printf("%.2lf\n",left);
}
}
二分-A - Cable master的更多相关文章
- [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 二分+精度
题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...
- POJ 1064 Cable master(二分查找+精度)(神坑题)
POJ 1064 Cable master 一开始把 int C(double x) 里面写成了 int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...
- poj 1064 Cable master 判断一个解是否可行 浮点数二分
poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...
- POJ 1064 Cable master (二分查找)
题目链接 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. ...
- Cable master(二分-求可行解)
Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Commi ...
- poj1064 Cable master(二分)
Cable master 求电缆的最大长度(二分法) Description Inhabitants of the Wonderland have decided to hold a region ...
- 【POJ - 1064】Cable master(二分)
Cable master Descriptions 输入2个数 N K n条绳子 要分成大于等于k段 求每段最长多长呢?并且每段不能小于1cm 必须以厘米精度写入数字,小数点后正好是两位数.如 ...
随机推荐
- 正规式与正规集,DFA与NFA
词法分析器的设计 词法分析器的功能:输入源程序.输出单词符号 词法分析器的设计:给出程序设计语言的单词规范--单词表, 对照单词表设计识别该语言所有单词的状态转换图, 根据状态转换图编写词法分析程序 ...
- layui table 表头和内容数据不能对齐
个人博客 地址:http://www.wenhaofan.com/article/20181224153019 今天使用layui table方法渲染时出现了个莫名其妙的错误 正常情况table应该是 ...
- jmeter-json提取器提取的内容含”引号
这时如果直接赋值会报错 解决方法: 1.用vars.get("Object")提取变量的值 2.用代码提取,最后把提取到的Object或Array转为String
- 从零开始一个个人博客 by asp.net core and angular(一)
这是一个个人叙述自己建设博客的帖子,既然是第一篇那肯定是不牵扯代码了,主要讲一下大体的东西,微软最新的web框架应该就数asp.net core 3.1了这是一个长期支持版,而且是跨平台又开源版本,所 ...
- SpringCloud踩坑
今天在使用 SpringCloud 时遇到了一个问题,感觉有不少小伙伴会遇到,所以记录下来 版本说明 SpringBoot 2.2.4.RELEASE SpringCloud Greenwich.SR ...
- Bilibili手机端下载的Download文件批量转换为MP4软件【Bilibili_DownVideoToMp4】原创发布
Bilibili手机端下载的Download文件批量转换为MP4软件[Bilibili_DownVideoToMp4]原创发布 起因 Bilibili手机端的视频下载下来只能在手机上看,手机屏幕太小看 ...
- AMBA简介
AMBA AMBA(Advanced Microcontroller Bus Architecture)先进的微控制器总线架构是一个免费.开放的标准,用于SoC内部功能模块之间的互连和管理.对成功设计 ...
- Auto-Encoder(自编码器)原理
1.无监督学习 无监督学习和监督学习是机器学习的两个方向,监督学习主要适用于已经标注好的数据集(如mnist分类问题),无监督学习则是希望计算机完成复杂的标注任务,简单的解释就是——教机器自己学习,它 ...
- opencv —— createTrackbar、getTrackbarPos 滑动条的创建和使用
创建滑动条:createTrackbar 函数 createTrackbar 函数用于创建一个可以调整数值的滑动条,并将滑动条附加在指定的窗口上. int createTrackbar(const s ...
- 【Android】java中调用JS的方法
最近因为学校换了新的教务系统,想做一个模拟登陆功能,发现登陆的账号和密码有一个js脚本来进行加密 整理了一下java中执行JS的方法 智强教务 账号 密码 加密方法 var keyStr = &quo ...