题目链接:http://poj.org/problem?id=1064

DescriptionInhabitants 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.
InputThe first line of the input file contains two integer numb ers N and K, separated by a space. N (1 = N = 10000) is the number of cables in the stock, and K (1 = K = 10000) 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 1 meter and at most 100 kilometers in length. All lengths in the input file are written with a centimeter precision, with exactly two digits after a decimal point.
OutputWrite 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 Input4 11
8.02
7.43
4.57
5.39
Sample Output2.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=-1;for(int i=0; i<n; i++){scanf("%lf",&a[i]);maxx=max(maxx,a[i]);}double l=0,r=maxx*100,ans=0;int mid;double mm;while(l<=r){mid=(l+r)/2;int sum=0;mm=(double)mid/100;for(int i=0; i<n; i++){sum+=(a[i]/mm);}if(sum<m)r=mid-1;else{l=mid+1;ans=mid;}}ans/=100;if(ans<0.01)printf("0.00\n");elseprintf("%.2f\n",ans);}return 0;
}

转载于:https://www.cnblogs.com/jun939026567/p/5788961.html

(poj)1064 Cable master 二分+精度相关推荐

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

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

  2. POJ 1064 -- Cable master(二分)

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

  3. POJ 1064 Cable master (二分答案,G++不过,C++就过了)

    题目: 这题有点坑,G++过不了,C++能过. 条件:n个数据a[],分成k段,结果精度要求两位小数. 问题:每段最长为多少? 思路:因为精度要求为两位小数,我先把所有的长度a[]*100. 我们对答 ...

  4. poj 1064 Cable master

    题意:给n段绳子,长度分别为c1,c2.....,切成相等的k段,求最大的长度 分析:二分长度,唯一注意的一点,输出的时候的精度 #include<iostream> #include&l ...

  5. poj 1064 java_poj 1064(二分答案)

    题意: 有N条绳子,长度分别为 length[1,2,3,........,N]. 如果从它们中切割出K条长度相同的绳子,这K条绳子每条最长有多长? 结果保留两位小数. 题解: 二分可能的长度. AC ...

  6. Cable master (POJ No.1064)

    二分搜索思想:bool C(double x)可以得到长度为x的绳子 //#define LOCAL #include<stdio.h> #include<math.h> in ...

  7. 二分法的应用:POJ1064 Cable master

    /* POJ1064 Cable master时间限制: 1000MS 内存限制: 10000K 提交总数: 58217 接受: 12146 描述Wonderland的居民已经决定举办地区性编程比赛. ...

  8. 电缆总管 Cable master(挑战程序设计竞赛)

    题目链接:电缆总管 Cable master(挑战程序设计竞赛) - ​​​​​​​​​ 题目大意: 给n条绳子的长度找k条绳子(长度相同)的最大长度 思路: 二分答案 代码: #include &l ...

  9. POJ - 1905 (几何+二分)

    POJ - 1905 (几何+二分) 题目正文如下: When a thin rod of length L is heated n degrees, it expands to a new leng ...

最新文章

  1. 健康日志之口腔粘膜----7-13
  2. 一条sql语句统计一个字段的不同条件, 无需过多子查询
  3. Algorithm:C++语言实现之贪心法算法相关问题
  4. 25、Sql语句执行顺序
  5. 产品经理如何高效的做用户调研?
  6. Android-完美解决在Activity中触摸返回键onBackPressed不能触发问题
  7. python制作安装包(setup.py)
  8. 10大最高效的Java库盘点
  9. 数据 3 分钟 | ShardingSphere 核心团队获融资、巨杉数据库发布湖仓一体架构多款产品...
  10. 重力加速度换算_压力的单位与换算
  11. java基础知识的一些细节问题
  12. 每日算法系列【LeetCode 881】救生艇
  13. 做外贸如何防止邮箱被封?已解决!
  14. 远程接入Linux、unix、Windows工具-opentext ETX
  15. cs224w(图机器学习)2021冬季课程学习笔记15 Frequent Subgraph Mining with GNNs
  16. html+怎么播放avi视频,视频格式怎么修改?
  17. 幼麟棋牌进入房间逻辑分析
  18. 常见色域基础知识与色域转换公式(YUV/YCbCr/YIQ/RGB/R‘G‘B‘/CMYK)
  19. 潘晓婷:19年的专注成就九球天后
  20. Linux内核学习系列(7)——execve与需求加载

热门文章

  1. Mysql高级考试题_MySQL高级应用答案试题题目及答案,期末考试题库,章节测验答案...
  2. java中整数如何表示,在Java中如何在位级别上内部表示整数?
  3. mysql主从配置错误_mysql主从配置失败,主从通讯失败
  4. Linux的md64进程,在Linux上安装Elasticsearch Kibaba.md(示例代码)
  5. python xlwt写入已有表_Python中,添加写入数据到已经存在的Excel文件
  6. 常用的基本Windows数据类型
  7. duilib自定义消息
  8. Java DataOutputStream writeUTF()方法及示例
  9. Object类的hashCode()方法
  10. 【汇编语言】除法(DIV/IDIV)