Cable master
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 49944   Accepted: 10493

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



题意:有N条绳子,他们的长度分别为Li。如果从他们中切割出k条长度相同的绳子的话,这k条绳子最长能有多长?答案保留小数点后两位。

思路:这个问题采用二分法很容易得到答案。
二分法模板:
int n,k;
const int maxn=1000;
int a[maxn];
void solve()
{
int lb=-1,ub=n;
while(ub-lb>1)
{
int mid=(lb+ub)/2;
if(a[mid]>=k)
ub=mid;
else
lb=mid;
}
printf("%d",ub);
}

题目ac代码:

#include <iostream>
#include<math.h>
#include<stdio.h>
using namespace std; const int maxn=10005;
double l[maxn];
int n,k;
const double inf=99999999; bool check(double x)
{
int sum=0;
for(int i=0;i<n;i++)
sum+=(int)(l[i]/x);
return sum>=k;
}
void solve()
{
double lb=0,ub=inf;
//重复循环,直到解的范围足够小
for(int i=0;i<100;i++)
{
double mid=(ub+lb)/2;
if(check(mid))
lb=mid;
else ub=mid;
}
printf("%.2f\n",floor(ub*100)/100);
}
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++)
{
scanf("%lf",&l[i]);
}
solve();
return 0;
}




















												

最新文章

  1. Linux下查看Nginx安装目录、版本号信息?
  2. 让jquery.tmpl.js支持index序号
  3. web socket 心跳包的实现方案
  4. 使用jsdoc-toolkit来自动生成js api文档
  5. sql server2008 搭建链接服务器成功后查询时报Cannot obtain the schema rowset &quot;DBSCHEMA_TABLES_INFO&quot; for OLE DB provider &quot;SQLNCLI10&quot; for linked server &quot;XXXXX&quot;. 的解决方法
  6. SQL SERVER2012 无法连接远程服务器
  7. cvc-elt.1: Cannot find the declaration of element &#39;beans&#39;Failed to read schema document &#39;http://www.springframework.org/schema/beans/spring- beans-3.0.xsd&#39;
  8. 最好用的jQuery-Ajax缓存插件
  9. 生产者消费者C++实现
  10. rpm 包的安装:
  11. C语言编程漫谈——main函数
  12. SQL 数据插入、删除 大数据
  13. AGC 014E.Blue and Red Tree(思路 启发式合并)
  14. February 9th, 2018 Week 6th Friday
  15. 打包maven后出现jar包丢失
  16. Memento Mori (二维前缀和 + 枚举剪枝)
  17. 【转载四】Grafana系列教程–Grafana基本概念
  18. 关于set_output_delay与set_input_delay概念与用法
  19. leetcode:Symmetric Tree【Python版】
  20. Microsoft Dynamics CRM4.0 和 Microsoft Dynamics CRM 2011 JScript 方法对比

热门文章

  1. 基于HttpClient4.5.2实现的HttpClient工具类
  2. PHP $_SERVER的使用
  3. [bzoj1895][Pku3580]supermemo_非旋转Treap
  4. 选择器的使用(nth-child和nth-last-child选择器)
  5. pymongo collection.save 问题
  6. NBUT 1450 Blitzcrank
  7. Kafka跨集群同步工具——MirrorMaker
  8. HDU1215--七夕节
  9. 关于ListView的setEmptyView没效果的问题
  10. react 引入 百度地图API