(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. ...
随机推荐
- 搭架私有Git服务器Gogs
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:搭架私有Git服务器Gogs.
- SVN遇到的几个错误问题解决办法
1.svn更新被锁 清理之后陷入死循环问题 Attempted to lock an already-locked dir svn: Working copy 'E:\Workspaces\eclip ...
- 数学之路(3)-机器学习(3)-机器学习算法-SVM[5]
svm小结 1.超平面 两种颜色的点分别代表两个类别,红颜色的线表示一个可行的超平面.在进行分类的时候,我们将数据点 x 代入 f(x) 中,如果得到的结果小于 0 ,则赋予其类别 -1 ,如果 ...
- Cocos2d-x 3.0心得(01)-图片载入与混合模式
近期開始用cocos2dx 3.0做东西,略有心(cao)得(dian),略微作下记录吧. v3.0相对v2.2来说,最引人注意的,应该是对触摸层级的优化.和lambda回调函数的引入(嗯嗯.不枉我改 ...
- Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 44 bytes) in
最近莫名出现这个错误. 研究一下原因很奇葩呢. 原因:sql获取数据库中数据,取出数据赋给变量,数据太多,超过memory_limit内存设置了. 解决方法:设置memory_limit不建议.优化代 ...
- js jquery 等的地址
jquery在线地址(jquery地址):http://code.jquery.com/jquery-latest.js js人脉图(关系图)插件: http://js.cytoscape.org/
- Vi、Vim及Gedit编辑器
搜索(注意,不需要输入:号.也可以先输入:号再键入命令) /string……………………向后搜索,从光标处向文件尾搜索,按n键继续搜索下一个 ?string……………………向前搜索 注意:搜索时会将所 ...
- C#_datatable 写入大量数据_BulkCopy
using Microsoft.Win32; using System; using System.Collections.Generic; using System.Configuration; u ...
- What Influences Method Call Performance in Java?--reference
reference from:https://www.voxxed.com/blog/2015/02/too-fast-too-megamorphic-what-influences-method-c ...
- 手把手教你使用UICollectionView写公司的项目
在很多app中都有这样通用的页面,一直没有机会使用UICollectionView,只是简单的看过他的使用方法.今天公司美工出图,使用了他,并且遇到了好多的坑.记录一下过程,不确定使用的方法是不是最优 ...