题目链接

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 (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.

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

4 11
8.02
7.43
4.57
5.39

Sample Output

2.00

AC

  • 二分枚举
  • 精度问题:可以转化为整数,也可以直接用小数
  • 小数
#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define N 10005
#define ll long long
#define P pair<int, int>
#define mk make_pair
using namespace std;double a[N];
int main() {
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);
#endifint n, m;while (scanf("%d%d", &n, &m) != EOF) {for (int i = 0; i < n; ++i) {scanf("%lf", &a[i]);} double l = 0, r = 100005;while ((r - l) > 1e-9) {double mid = (l + r) / 2.0;int sum = 0;for (int i = 0; i < n; ++i) {sum += a[i] / mid;}if (sum >= m)   l = mid;else    r = mid;}// 这里要输出右区间,具体不太清楚。printf("%.2f\n", floor(r * 100) / 100.0);}return 0;
} 
  • 整数
#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define N 10005
#define ll long long
#define P pair<int, int>
#define mk make_pair
using namespace std;int a[N];
int main() {
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);
#endifint n, m;while (scanf("%d%d", &n, &m) != EOF) {for (int i = 0; i < n; ++i) {double len;scanf("%lf", &len);a[i] = len * 100;} int l = 1, r = 10000500;while (l <= r) {int mid = (l + r) >> 1;int sum = 0;for (int i = 0; i < n; ++i) {sum += a[i] / mid;}if (sum >= m)   l = mid + 1;else    r = mid - 1;}printf("%.2f\n", double(r) / 100);}return 0;
} 

POJ 1064 -- Cable master(二分)相关推荐

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

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

  2. (poj)1064 Cable master 二分+精度

    题目链接:http://poj.org/problem?id=1064 DescriptionInhabitants of the Wonderland have decided to hold a ...

  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. 电缆总管 Cable master(挑战程序设计竞赛)

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

  8. POJ 2251 Dungeon Master(三维BFS求最短路径)

    3D dungeon 时间限制: 1 Sec  内存限制: 128 MB 提交: 2  解决: 2 [提交][状态][讨论版][命题人:201506020829][Edit] [TestData] 题 ...

  9. POJ 1966 Cable TV Network (最大流最小割)

    $ POJ~1966~Cable~TV~Network $ $ solution: $ 第一眼可能让人很难下手,但本就是冲着网络流来的,所以我们直接一点.这道题我们要让这个联通图断开,那么势必会有两个 ...

最新文章

  1. 【基础知识】如何在浏览器中查找元素属性节点
  2. [ NOI 2002 ] Robot
  3. response.setHeader()的用法
  4. 做一个java项目要经过那些正规的步骤
  5. php中var_dump()函数
  6. *【CodeForces - 195B】After Training (多解,模拟)
  7. Two-Stream RNN/CNN for Action Recognition in 3D Videos-阅读笔记
  8. Retrofit使用
  9. java递归方法分析
  10. C++自学17:goto
  11. CSS3和jQuery实现的自定义美化Checkbox和Radiobox
  12. 计算机网络与通讯教案,计算机网络技术教案.docx
  13. It彭于晏带你学JAVA之适配器模式及API
  14. 蓝牙追踪_如何使用蓝牙追踪器跟踪您的东西
  15. 今日的质量,明日的市场--谈谈软件登记测试
  16. linux快速入门 快捷高效学习方法
  17. 办公知识:有关如何PDF转Word文档的方法分享
  18. python分组统计标准化_分组计算和汇总_Python数据分析实战应用_数据挖掘与分析视频-51CTO学院...
  19. 使用显卡程序加速(opencl、cuda)
  20. [观点]诺基亚是如何衰落的

热门文章

  1. git clone 失败
  2. Linux之nfs服务
  3. BAD APPLE C++控制台程序
  4. linux系统下开机启动流程
  5. ACM学习历程—Hihocoder 1290 Demo Day(动态规划)
  6. 用官方2012版本131兆,一共有四个自带软件
  7. 一步一步学Silverlight 2系列(22):在Silverlight中如何用JavaScript调用.NET代码
  8. (转)[EntLib]微软企业库5.0 学习之路——第十步、使用Unity解耦你的系统—PART2——了解Unity的使用方法(1)...
  9. [基础题] * 9.(*)设计一个Student接口,以一维数组存储一个班级的学生姓名。
  10. App设计灵感之十二组精美的智能家居操作App设计案例