Cable master(好题,二分)
Cable master
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2473 Accepted Submission(s): 922
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).
#include<stdio.h>
double m[];
int N;double sum,K;
double search(){int temp=;
double l=,r=sum/K,mid;
while(r-l>1e-){temp=;
mid=(l+r)/;
for(int i=;i<N;++i)temp+=(int)(m[i]/mid);//temp代表能裁剪成的数量。。。
if(temp>=K)l=mid;
else r=mid;
}
return mid;
}
int main(){
while(scanf("%d%lf",&N,&K),N||K){sum=;
for(int i=;i<N;++i)scanf("%lf",&m[i]),sum+=m[i];
printf("%.2lf\n",search());
}
return ;
}
poj ac:
#include<stdio.h>
double m[];
int N;double sum,K;
double search(){int temp=;
double l=,r=sum/K,mid;
while(r-l>1e-){temp=;
mid=(l+r)/;
for(int i=;i<N;++i)temp+=(int)(m[i]/mid);
if(temp>=K)l=mid;
else r=mid;
}
return r;
}
int main(){double d;double t;
while(~scanf("%d%lf",&N,&K)){sum=;
for(int i=;i<N;++i)scanf("%lf",&m[i]),sum+=m[i];
d=search();
/// t=100*d;printf("%d\n",t);
printf("%.2f\n",(int)(d*)/100.0);
}
return ;
}
Cable master(好题,二分)的更多相关文章
- poj 1064 Cable master【浮点型二分查找】
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29554 Accepted: 6247 Des ...
- Cable master poj1064(二分)
http://poj.org/problem?id=1064 题意:共有n段绳子,要求总共被分为k段.问在符合题意的前提下,每段长最大是多少? #include <iostream> #i ...
- Cable master(二分题 注意精度)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26596 Accepted: 5673 Des ...
- POJ 1064 Cable master(二分查找+精度)(神坑题)
POJ 1064 Cable master 一开始把 int C(double x) 里面写成了 int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...
- [ACM] poj 1064 Cable master (二分查找)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21071 Accepted: 4542 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 判断一个解是否可行 浮点数二分 题目链接: 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 ...
随机推荐
- jquery.validate详解二
五.常用方法及注意问题 1.用其他方式替代默认的SUBMIT $().ready(function() { $("#signupForm").validate({ ...
- c++面试知识点
static #include<stdio.h> #include<iostream> #include<assert.h> using namespace std ...
- 07_DICTIONARY_ACCESSIBILITY
07_DICTIONARY_ACCESSIBILITY 控制对系统权限的限制: TRUE 有相应系统权限,允许访问SYS下的对象. FALSE 确保拥有可以访问任何对象的系统权限,但不可以访问SYS下 ...
- NET基础课--Linq第一讲
在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之前,在声明一个变量的时候, 总是要为一个变量指定他的类型甚至在foreach一 ...
- Sql Server中charindex、patindex的区别
SQL代码如下: select charindex('1,','121,1,1234') select patindex('%1,%','121,1,1234') ','121,1,1234') se ...
- C++重难点知识
1.顶层const和底层const const int a=10; int b=5; const int *p1=&a; int (*const)p2=&b; p1是顶层const,表 ...
- CentOS安装配置ganglia
1. 下载ganglia源码包并解压 wget http://sourceforge.net/projects/ganglia/files/ganglia%20monitoring%20cor ...
- mysql 复习与学习(二)数据库及表结构的创建删除
mysql -h localhost -uroot -p123456 //连接数据库 show databases; //查看数据库 create database if not exists db_ ...
- Array类型(一)
1.创建数组的基本方式有两种,第一种使用Array构造函数 使用Array构造函数时可以省略new操作符 2.第二种方式是使用数组字面量表示法 由于IE的实现与其他浏览器不一致,因此我们不赞同使用这个 ...
- 宽带连接工具[bat]
功能概述: 本工具使用批处理编写,提供自动判断网络状态以决定断开或是连上网络,本月已用宽带时长,到月初自动清零.提供联网日志功能,可以记录下所有的连接或断开网络记录.如果连接失败,自动提示输入密码,特 ...