题目链接: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 二分+精度的更多相关文章

  1. POJ 1064 Cable master | 二分+精度

    题目: 给n个长度为l[i](浮点数)的绳子,要分成k份相同长度的 问最多多长 题解: 二分长度,控制循环次数来控制精度,输出也要控制精度<wa了好多次> #include<cstd ...

  2. POJ 1064 Cable master (二分答案)

    题目链接:http://poj.org/problem?id=1064 有n条绳子,长度分别是Li.问你要是从中切出m条长度相同的绳子,问你这m条绳子每条最长是多少. 二分答案,尤其注意精度问题.我觉 ...

  3. poj 1064 Cable master 二分 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=1064 题解 二分即可 其实 对于输入与精度计算不是很在行 老是被卡精度 后来学习了一个函数 floor 向负无穷取整 才能ac 代码如下 ...

  4. [POJ] 1064 Cable master (二分查找)

    题目地址:http://poj.org/problem?id=1064 有N条绳子,它们的长度分别为Ai,如果从它们中切割出K条长度相同的绳子,这K条绳子每条最长能有多长. 二分绳子长度,然后验证即可 ...

  5. POJ 1064 Cable master (二分)

    题意:给定 n 条绳子,它们的长度分别为 ai,现在要从这些绳子中切出 m 条长度相同的绳子,求最长是多少. 析:其中就是一个二分的水题,但是有一个坑,那么就是最后输出不能四舍五入,只能向下取整. 代 ...

  6. POJ 1064 Cable master(二分查找+精度)(神坑题)

    POJ 1064 Cable master 一开始把 int C(double x) 里面写成了  int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...

  7. poj 1064 Cable master 判断一个解是否可行 浮点数二分

    poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...

  8. 二分搜索 POJ 1064 Cable master

    题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algo ...

  9. POJ 1064 Cable master (二分查找)

    题目链接 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. ...

随机推荐

  1. ASP.Net 使用SqlBulkCopy批量插入

    批量插入,以前我的做法是生成一堆insert into的sql语句,然后用程序一次值行,来实现. 今天看到了ASP.Net里可以使用DataTable,先将数据写入到DataTable中,然后使用Sq ...

  2. OpenCV训练分类器制作xml文档

    OpenCV训练分类器制作xml文档 (2011-08-25 15:50:06) 转载▼ 标签: 杂谈 分类: 学习 我的问题:有了opencv自带的那些xml人脸检测文档,我们就可以用cvLoad( ...

  3. java System 常用方法

    一.System.currentTimeMillis() 获取系统当前时间,毫秒 二.System.getProperty Java.version Java 运行时环境版本 java.vendor ...

  4. int、bigint、smallint 和 tinyint

    Transact-SQL 参考 int.bigint.smallint 和 tinyint 使用整数数据的精确数字数据类型. bigint 从 -2^63 (-9223372036854775808) ...

  5. iOS 根据文件名获取到文件路径

    根据文件名来获取文件路径(Document目录下) //根据文件名来获取文件路径 - (NSString *)dataFilePath:(NSString *)sender { NSArray *pa ...

  6. C++ Primer 学习笔记_76_模板与泛型编程 --模板定义[续]

    模板与泛型编程 --模板定义[续] 四.模板类型形參 类型形參由keywordclass或 typename后接说明符构成.在模板形參表中,这两个keyword具有同样的含义,都指出后面所接的名字表示 ...

  7. Windows下记事本编辑的Shell脚本放到Linux下执行出错,格式问题(/bin/bash^M: bad interpreter: 没有那个文件或目录)

    错误: /bin/bash^M: bad interpreter: 没有那个文件或目录 解决方案: 运行脚本时出现了这样一个错误,打开之后并没有找到所谓的^M,查了之后才知道原来是文件格式的问题,也就 ...

  8. OpenVPN 如何记住用户名和密码

    最近在使用OpenVPN,但是没有记住用户名和密码功能,太坑人,研究一下发现是可以的. 1. 在OpenVPN安装目录下\OpenVPN\config文件夹中找到vpnserver.ovpn文件. 2 ...

  9. C 双向链表

    单链表的结点都只有一个指向下一个结点的指针 单链表的数据元素无法直接访问其前驱元素 逆序访问单链表中的元素是极其耗时的操作! len = LinkList_Length(list); for (i=l ...

  10. 王帅:深入PHP内核

    [问底]王帅:深入PHP内核(三)——内核利器哈希表与哈希碰撞攻击   [问底]王帅:深入PHP内核(二)——SAPI探究   [问底]王帅:深入PHP内核(一)——弱类型变量原理探究