Cable master
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 37865   Accepted: 8051

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

Source

 
 
 
解析:二分即可。
 
 
 
#include <cstdio>
#include <cmath> double a[10005];
int n, k; bool ok(double x)
{
int num = 0;
for(int i = 0; i < n; ++i){
num += (int)(a[i]/x);
}
return num >= k;
} int main()
{
scanf("%d%d", &n, &k);
for(int i = 0; i < n; ++i)
scanf("%lf", &a[i]);
double l = 0, r = 1e5+5;
for(int i = 1; i < 100; ++i){
double mid = (l+r)/2;
if(ok(mid)) l = mid;
else r = mid;
}
printf("%.2f\n", floor(l*100)/100);
return 0;
}

  

最新文章

  1. Codeforces Round #167 (Div. 2)
  2. 【ASP.NET 问题】System.InvalidOperationException: 对象的当前状态使该操作无效 【大量表单数据提交】错误解决
  3. C语言练习题_北理工的恶龙
  4. CF 19D 线段树+set压缩坐标轴+离散化map
  5. SetTimer 和 OnTimer 的使用
  6. VS2013中使用GDI+绘图
  7. HDU 1039 -Easier Done Than Said?
  8. Buenos Aires和Rio de Janeiro怎么发音?
  9. 学习新手给Android新手的一些学习建议
  10. vscode快捷键大全
  11. vue用mand-mobile ui做交易所移动版实战示例
  12. springboot笔记1(转载于puresmile)
  13. Python学习积累:使用help();打印多个变量;fileno()
  14. Python+Excel+Unittest+HTMLTestRunner实现数据驱动接口自动化测试(二)
  15. (后端)注意hibernate中对象的set方法修改数据库
  16. Linux内核设计与实现 第三章
  17. Libevent源码分析—event_add()
  18. IOPS计算
  19. react 写一个贪吃蛇
  20. &lt;&lt;网络是怎样连接的&gt;&gt;笔记第2章用电信号传输Tcp/ip数据

热门文章

  1. HDU4758 Walk Through Squares AC自动机&amp;&amp;dp
  2. mac上eclipse上配置hadoop
  3. ****Git 常用命令和使用思维导图
  4. lintcode:最大子数组II
  5. *[hackerrank]Jim Beam
  6. asp.net中当服务器出错时显示指定的错误页面
  7. JavaScript DOM编程基础精华03(动态设置,层的操作,性能问题)
  8. HTML基础和表格
  9. firebug的使用方法和技巧(web开发调试工具)
  10. jQuery EasyUI - Add link to datagrid cell