POJ1063Cable master(二分搜索)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 36288 | Accepted: 7743 |
Description
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
Output
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
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
const int MAXN=;
const double ESP=1.0e-6;
int n,k;
double cab[MAXN];
double test(double l)
{
int s=;
for(int i=;i<n;i++)
{
s+=(int)(cab[i]/l);
}
return s>=k;
}
int main()
{
while(cin>>n>>k)
{
for(int i=;i<n;i++)
{
cin>>cab[i];
}
double l=0.0;
double r=100000000.0;
while(fabs(r-l)>ESP)
{
double mid=(l+r)/;
if(test(mid)) l=mid;
else r=mid;
}
double res=floor(r*)/100.0;
cout<<showpoint<<setprecision()<<fixed<<res<<endl;
}
return ;
}
POJ1063Cable master(二分搜索)的更多相关文章
- Poj:1064 : :Cable master (假定一个解并判断是否可行)(二分搜索答案)
Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...
- 二分搜索 POJ 1064 Cable master
题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algo ...
- POJ 1064 Cable master (二分)
题目链接: 传送门 Cable master Time Limit: 1000MS Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...
- 不光是查找值! "二分搜索"
2018-11-14 18:14:15 二分搜索法,是通过不断缩小解的可能存在范围,从而求得问题最优解的方法.在程序设计竞赛中,经常会看到二分搜索法和其他算法相结合的题目.接下来,给大家介绍几种经典的 ...
- 二分搜索 - Binary Search
二分搜索是一种在有序数组中寻找目标值的经典方法,也就是说使用前提是『有序数组』.非常简单的题中『有序』特征非常明显,但更多时候可能需要我们自己去构造『有序数组』.下面我们从最基本的二分搜索开始逐步深入 ...
- C++分治策略实现二分搜索
问题描述: 给定已排好序的n个元素组成的数组,现要利用二分搜索算法判断特定元素x是否在该有序数组中. 细节须知: (1)由于可能需要对分治策略实现二分搜索的算法效率进行评估,故使用大量的随机数对算法进 ...
- 不光是查找值!"二分搜索"
从有序数组中查找某个值 问题描述:给定长度为n的单调不下降数列a0,…,an-1和一个数k,求满足ai≥k条件的最小的i.不存在则输出n. 限制条件:1≤n≤1060≤a0≤a1≤…≤an-1< ...
- xamarin MasterDetailPage点击Master时卡顿现象
在很多项目中经常会使用到MasterDetailPage的布局方式,而且一般做为主页面来开发,在开发中,发现一个并不算Bug的问题,但是却发生了,以此记录下来,方便大家探讨. 现象是这样的,我开发了一 ...
- backup3:master 数据库的备份和还原
在SQL Server 中,master 数据库记录系统级别的元数据,例如,logon accounts, endpoints, linked servers, and system configur ...
随机推荐
- gradle配置笔记
apply plugin 使用插件 group 包名 version 项目版本 sourceCompatibility 指定编译.java文件的jdk版本 targetCompatibility 确保 ...
- ASP.NET MVC 5 访问在views文件夹中的JS文件。 ASP.NET MVC html与JS分离
修改VIEWS文件夹下的web.config文件, 加入下面红色字标识的内容: <system.webServer> <handlers> <r ...
- POJ 1144 无向图求割点
学长写的: #include<cstdio>#include<cstdlib>#include<cmath>#include<iostream>#in ...
- Mysql 导出导入
MySQL数据库导出 以root登录vps,执行以下命令导出. 1./usr/local/mysql/bin/mysqldump -u root -p123456 zhumaohai > /ho ...
- vs+mysql+ef配置方法
这次的项目用的是MySQL数据库,但是ADO.NET实体数据模型默认是不支持MySQL数据库的,本文档将介绍如何让VS ADO.NET实体数据模型支持MySQL. 一.安装插件 1.VS插件 mysq ...
- mongodb 的安装(Centor OS )
1.下载地址 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.2.tgz 2.解压.配置 tar zxvf mongodb ...
- Android 实现http通信(servlet做服务器端) HttpClient、HttpURLConnection实现登录验证
一,写好服务器端 在eclipse或其它javaee开发工具中新建一个web项目(我这里的项目名是:Android),建一个servlet(我这里的servlet名是:LoginServlet),模拟 ...
- codeforces707A:Brain's Photos
Description Small, but very brave, mouse Brain was not accepted to summer school of young villains. ...
- jQuery Fancybox插件使用参数详解
Fancybox的特点如下: 可以支持图片.html文本.flash动画.iframe以及ajax的支持 可以自定义播放器的CSS样式 可以以组的形式进行播放 如果将鼠标滚动插件(mouse whee ...
- PostMan使用教程(1)
Postman介绍 Postman是google开发的一款功能强大的网页调试与发送网页HTTP请求,并能运行测试用例的的Chrome插件.其主要功能包括: 模拟各种HTTP requests 从常用的 ...