(poj)1064 Cable master 二分+精度
题目链接:http://poj.org/problem?id=1064
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.
Input The first line of the input file contains two integer numb ers N and K, separated by a space. N ( = N = ) is the number of cables in the stock, and K ( = K = ) 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 meter and at most 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).
Sample Input 8.02
7.43
4.57
5.39
Sample Output 2.00
题意:有N个棍可截取,问截取k个等长的棍的最大长度 如果小于0.01输出0.00
方法:把最长的二分,但是需要考虑精度问题,可以吧二分的范围都乘以100,去掉精度误差
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
#define N 10010
#define INF 0x3f3f3f3f
#define ll long long
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
double a[N];
int main()
{
int n,m;
double maxx;
while(scanf("%d %d",&n,&m)!=EOF)
{
maxx=-;
for(int i=; i<n; i++)
{
scanf("%lf",&a[i]);
maxx=max(maxx,a[i]);
}
double l=,r=maxx*,ans=;
int mid;
double mm;
while(l<=r)
{
mid=(l+r)/;
int sum=;
mm=(double)mid/;
for(int i=; i<n; i++)
{
sum+=(a[i]/mm);
}
if(sum<m)
r=mid-;
else
{
l=mid+;
ans=mid;
} }
ans/=;
if(ans<0.01)
printf("0.00\n");
else
printf("%.2f\n",ans);
}
return ;
}
(poj)1064 Cable master 二分+精度的更多相关文章
- POJ 1064 Cable master | 二分+精度
题目: 给n个长度为l[i](浮点数)的绳子,要分成k份相同长度的 问最多多长 题解: 二分长度,控制循环次数来控制精度,输出也要控制精度<wa了好多次> #include<cstd ...
- POJ 1064 Cable master (二分答案)
题目链接:http://poj.org/problem?id=1064 有n条绳子,长度分别是Li.问你要是从中切出m条长度相同的绳子,问你这m条绳子每条最长是多少. 二分答案,尤其注意精度问题.我觉 ...
- poj 1064 Cable master 二分 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=1064 题解 二分即可 其实 对于输入与精度计算不是很在行 老是被卡精度 后来学习了一个函数 floor 向负无穷取整 才能ac 代码如下 ...
- [POJ] 1064 Cable master (二分查找)
题目地址:http://poj.org/problem?id=1064 有N条绳子,它们的长度分别为Ai,如果从它们中切割出K条长度相同的绳子,这K条绳子每条最长能有多长. 二分绳子长度,然后验证即可 ...
- POJ 1064 Cable master (二分)
题意:给定 n 条绳子,它们的长度分别为 ai,现在要从这些绳子中切出 m 条长度相同的绳子,求最长是多少. 析:其中就是一个二分的水题,但是有一个坑,那么就是最后输出不能四舍五入,只能向下取整. 代 ...
- 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
题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algo ...
- POJ 1064 Cable master (二分查找)
题目链接 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. ...
随机推荐
- JSP九大内置对象分析
JSP九大内置对象分为三类: 1.输入输出对象:out对象.response对象.request对象 2.通信控制对象:pageContext对象.session对象.application对象 3. ...
- 解决SenTestingKit/SenTestingKit.h: No such file or directory
在一个iOS项目中引入了单元测试,感觉项目间的依赖关系有些乱,就建了一个新的Project,再把原来的.h和.m加进去,编译时竟然出现“SenTestingKit/SenTestingKit.h: N ...
- JNI总结(一)
JNI 是 Java平台中的一个强大特性.应用程序能够通过 JNI把 C/C++代码集成进 Java程序中.通过 JNI.开发人员在利用 Java平台强大功能的同一时候,又不必放弃对原有代码的投资.由 ...
- Eclipse安装ADT失败解决办法
Eclipse的版本是3.5.2,配置Android的开发环境时遇到问题…… 按照Android官方文档一步步安装,到了安装Eclipse的ADT插件时,提示“requires 'org.eclips ...
- Xdebug+phpstorm配置
首先,把自己参考的网上材料的连接黏贴出来,是英文的,但是讲解的很详细,有兴趣的同学可以看一下. 1.http://blog.jetbrains.com/webide/2011/02/zero-conf ...
- PAT 1008
1008. Elevator (20) The highest building in our city has only one elevator. A request list is made u ...
- C#连接SQL SERVER数据库的详细步骤!
首先,在SQL SEVER里建立一个名为“Exercise”的数据库名,在该数据库下建立一张名为“lianxi”的表.好,现在开始写代码. 在FORM1里拖一个DATAGIRDVIEW用于显示表, ...
- jQuery中要注意的一些函数
has()方法 或 :has选择器 :是过滤子类含有的,并不是过滤当前选择器选择的元素或对象含有的
- 动态修改 C 语言函数的实现
Objective-C 作为基于 Runtime 的语言,它有非常强大的动态特性,可以在运行期间自省.进行方法调剂.为类增加属性.修改消息转发链路,在代码运行期间通过 Runtime 几乎可以修改 O ...
- 转--object-C 与lua使用wax交互
[51CTO独家译文]2011年6月的编程语言排行榜Lua语言一军突起,一举进入前十名.这与一年前苹果决定在iOS系统上使用Lua语言密不可分.但是,你了解如何用Lua语言在iOS上开发应用吗?51C ...