hdu 1551 Cable master (二分法)
Cable master
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1428 Accepted Submission(s): 522
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.
The input is ended by line containing two 0's.
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).
8.02
7.43
4.57
5.39
0 0
//187MS 320K 650 B G++
/* 题意:
给你n块木板,长为ai,要用这些木板分成k块等长的木板,问最长可为多长 二分法:
和之前某题一样的想法,就是计算出当长度为x时可得到的木板块数是否符合
然后几时二分的思想做。 */
#include<stdio.h>
#include<string.h>
double a[];
int n,k;
int fac(double x)
{
int cnt=;
for(int i=;i<n;i++)
cnt+=(int)(a[i]/x);
return cnt;
}
int main(void)
{
while(scanf("%d%d",&n,&k),n+k)
{
double l=;
double r=;
for(int i=;i<n;i++){
scanf("%lf",&a[i]);
r+=a[i];
}
r/=k;
while(r-l>=0.00001){
double mid=(r+l)/;
int m=fac(mid);
if(m>=k) l=mid;
else if(m<k) r=mid;
}
//printf("%d\n",fac(r));
printf("%.2lf\n",l);
}
return ;
}
hdu 1551 Cable master (二分法)的更多相关文章
- HDU 1551 Cable master
题解:很显然的二分检索,在算法艺术上看过原题,不过这里要注意精度: #include <cstdio> int n,m; ]; bool test(double x){ ,i; ;i< ...
- HDU 1551 Cable master【二分答案】
题意:给出n块木板,它们分别的高度,现在要把它们裁切成k块,问裁切成的最大的高度 二分答案,上限是这n块木板里面的最大值 然后每一个答案去判断一下是否满足能够裁切成k块 #include<ios ...
- POJ 1064 Cable master (二分法+精度控制)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65358 Accepted: 13453 De ...
- Cable master 求电缆的最大长度(二分法)
Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...
- 二分法的应用:POJ1064 Cable master
/* POJ1064 Cable master 时间限制: 1000MS 内存限制: 10000K 提交总数: 58217 接受: 12146 描述 Wonderland的居民已经决定举办地区性编程比 ...
- Cable master--hdu1551(二分法)
Cable master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- poj1064 Cable master(二分)
Cable master 求电缆的最大长度(二分法) Description Inhabitants of the Wonderland have decided to hold a region ...
- POJ 1064 Cable master (二分)
题目链接: 传送门 Cable master Time Limit: 1000MS Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...
- [ACM] poj 1064 Cable master (二分查找)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21071 Accepted: 4542 Des ...
随机推荐
- 13、SpringBoot------整合shiro
开发工具:STS 前言: shiro,一套简单灵活的安全权限管理框架. 把所有对外暴露的服务API都看作是一种资源,那么shiro就是负责控制哪些可以获得资源,哪些不能获取. 一个比较不错的教程:ht ...
- C#如何表格型数据导出到Excel?
代码如下: int intDataCount = myData.Tables[0].Rows.Count; Microsoft.Office.Interop.Excel.Application app ...
- vue的生命周期和路由守卫
组件相关钩子函数: beforeCreate.created.beforeMount.mounted.beforeUpdate.updated.beforeDestroy.destoryed 还有 ...
- 泉五培训Day4
T1 收果子 题目 [题目描述] 有一个果园,有n棵果树依次排成一排,其中已知第 i 棵果树上结了ai个果子.现在要按照果树编号顺序依次收果子,对于一个能装v个果树的果篮,收果子从第1棵果树开始,如果 ...
- MySQL 5.7基于GTID的主从复制环境搭建(一主一从)
Preface As wel all know,replication base on GTID with row format of binary log is comprehens ...
- TCPIP协议编程:基于UDP协议的局域网聊天工具的研发
任务目标 聊天器采用客户端/服务器(C/S)模式: 客户端利用UDP与服务器相连,客户端与客户端之间通过UDP相互通信: 服务器端具有服务器端口设置维护客户端个人信息,记录客户端状态,分配账号等: 客 ...
- Xtrabackup实现MySQL备份
一.xtrabackup介绍 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写)它由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上 ...
- lvs+ipvsadm负载均衡
使用LVS实现负载均衡原理及安装配置详解 负载均衡集群是 load balance 集群的简写,翻译成中文就是负载均衡集群.常用的负载均衡开源软件有nginx.lvs.haproxy,商业的硬件负载均 ...
- php-5.6.26源代码 - 扩展模块的种类,扩展模块的执行埋点
模块种类(两种) 类型一:zend的模块:(类似zend_extension=test.so) 识别方法: php.ini中以zend_extension开头的配置,如zend_extension=t ...
- [BZOJ2734][HNOI2012] 集合选数(状态压缩+思维)
Description 题目链接 Solution 可以根据条件构造出一个矩阵, 1 3 9 27 81... 2 6 18.... 4 12 36... 这个矩阵满足\(G[i][1]=G[i-1] ...