A - Cable master

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.

InputThe input consists of several testcases. The first line of each testcase contains two integer numbers 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 centimeter and at most 100 kilometers in length. All lengths in the input are written with a centimeter precision, with exactly two digits after a decimal point.

The input is ended by line containing two 0's.
OutputFor each testcase write to the output 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 must contain the single number "0.00" (without quotes).
Sample Input

  1. 4 11
  2. 8.02
  3. 7.43
  4. 4.57
  5. 5.39
  6. 0 0

Sample Output

  1. 2.00
  1.  
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. double a[];
  5. int n,k;
  6. int solve(double x){//用于判断按照长度x分割,能不能得到大于等于需求量k
  7. int sum=;
  8. for(int i=;i<n;i++)
  9. sum += a[i]/x;
  10. if(sum >= k) return ;
  11. else return ;
  12. }
  13.  
  14. int main(){
  15. double right = 0.0;
  16. while(~scanf("%d %d", &n, &k) && n && k){
  17. for(int i=; i<n; i++){
  18. scanf("%lf", &a[i]);
  19. if(a[i]>right) right = a[i];//找到长度最大量最为二分的右值
  20. }
  21. double mid, left=a[]/k;
  22. while(right-left > 1e-){
  23. mid = (right + left)/;
  24. if(solve(mid)) left = mid;
  25. else right = mid;
  26. }
  27. printf("%.2lf\n",left);
  28. }
  29. }
  1.  
  1.  

二分-A - Cable master的更多相关文章

  1. [ACM] poj 1064 Cable master (二分查找)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21071   Accepted: 4542 Des ...

  2. Cable master(二分题 注意精度)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26596   Accepted: 5673 Des ...

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

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

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

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

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

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

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

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

  7. Cable master(二分-求可行解)

    Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Commi ...

  8. poj1064 Cable master(二分)

    Cable master 求电缆的最大长度(二分法)   Description Inhabitants of the Wonderland have decided to hold a region ...

  9. 【POJ - 1064】Cable master(二分)

    Cable master Descriptions 输入2个数 N  K n条绳子    要分成大于等于k段 求每段最长多长呢?并且每段不能小于1cm 必须以厘米精度写入数字,小数点后正好是两位数.如 ...

随机推荐

  1. idea unable to import maven see logs for details

    问题描述 环境IEAD,Maven3.6.2 2019-09-09 17:29:10,751 [ 839683] ERROR - #org.jetbrains.idea.maven - Intelli ...

  2. 基于Jupyter Notebooks的C# .NET Interactive安装与使用

    .NET Interactive发布预览版了,可以像Python那样用jupyter notebooks来编辑C#代码.具体可以在GitHub上查看dotnet/interactive项目. 安装步骤 ...

  3. 如何在 vue 中添加权限控制管理?---vue中文社区

    前言 在一个项目中,一些功能会涉及到重要的数据管理,为了确保数据的安全,我们会在项目中加入权限来限制每个用户的操作.作为前端,我们要做的是配合后端给到的权限数据,做页面上的各种各样的限制. 需求 因为 ...

  4. POJ-2299 Ultra-QuickSort(用树状数组求逆序对数)

    题目链接 ac代码 #include<iostream> #include<cstdio> #include<cstring> #include<algori ...

  5. mybatis配置---> mybatisConfig.xml 配置加接数据源

    mybatisConfig.xml 配置主要作用是连接数据源配置的前提是在完成mybatis的jar包基础之上进行的同时要确保数据用户名和密码是否正确 一:密码写在 mybatisConfig.xml ...

  6. SpringBoot图文教程6—SpringBoot中过滤器的使用

    有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文系列教程技术大纲 鹿老师的Java笔记 SpringBo ...

  7. Linux DMA访问的一致性

    DMA访问的一致性 DMA对内存是直接访问的,而CPU对内存的访问有时会通过cache.不管是CPU还是DMA访问内存,都需要确保cache的一致性.本文只分析从DMA的角度,对内存的访问如何确保ca ...

  8. 使用VConsole调试代码

    在真实手机上运行H5页面时,无法看到控制台.为了能在真实手机上使用控制台,可以加入如下代码实现控制台: //引入vconsole var isTestEnvironment =true if(isTe ...

  9. Android中创建一个BroadcastReceiver

    首先创建一个java类继承BroadcastReceiver类 package com.example.service; import android.content.BroadcastReceive ...

  10. Mac下maven安装

    1.下载路径:https://maven.apache.org/download.cgi 要想查看历史版本:则点击archives. 点击binaries 就可以下载对应的maven. Binary ...