Cable master--hdu1551(二分法)
Cable master
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2499 Accepted Submission(s):
936
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.
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.
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).
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
double L[];
int a,b,i;
bool F(double x)
{
int sum=;
for(i=;i<a;i++)
sum +=(int)(L[i]/x);
return sum >= b;
}
void ww()
{
double l=,r=,mid;
while(r-l>1e-)
{
mid=(r+l)/;
if(F(mid))
l=mid;
else
r=mid;
}
r=(int)(r*)/100.0;
printf("%.2f\n",r);
}
int main()
{
scanf("%d%d",&a,&b);
for(i=;i<a;i++)
scanf("%lf",&L[i]);
ww(); return ;
}
Cable master--hdu1551(二分法)的更多相关文章
- POJ 1064 Cable master (二分法+精度控制)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65358 Accepted: 13453 De ...
- hdu 1551 Cable master (二分法)
Cable master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Cable master 求电缆的最大长度(二分法)
Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...
- HDU1551&&HDU1064 Cable master 2017-05-11 17:50 38人阅读 评论(0) 收藏
Cable master Time Limit: ...
- 二分法的应用:POJ1064 Cable master
/* POJ1064 Cable master 时间限制: 1000MS 内存限制: 10000K 提交总数: 58217 接受: 12146 描述 Wonderland的居民已经决定举办地区性编程比 ...
- poj1064 Cable master(二分)
Cable master 求电缆的最大长度(二分法) Description Inhabitants of the Wonderland have decided to hold a region ...
- POJ 1064 Cable master (二分)
题目链接: 传送门 Cable master Time Limit: 1000MS Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...
- [ACM] poj 1064 Cable master (二分查找)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21071 Accepted: 4542 Des ...
- Cable master(二分题 注意精度)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26596 Accepted: 5673 Des ...
- POJ 1064 Cable master
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37865 Accepted: 8051 Des ...
随机推荐
- gulp压缩js
1.安装nodejs -> 全局安装gulp -> 项目安装gulp以及gulp插件 -> 配置gulpfile.js -> 运行任务 2.查看nodejs的版本号 3.npm ...
- POJ1094 拓扑排序
问题:POJ1094 本题考查拓扑排序算法 拓扑排序: 1)找到入度为0的点,加入已排序列表末尾: 2)删除该点,更新入度数组. 循环1)2)直到 1. 所有点都被删除,则找到一个拓扑 ...
- C++之------构造函数
创建一个对象时,常常需要作某些初始化的工作,例如对数据成员赋初值. 类的数据成员是不能在声明类时初始化的. class Time { public : //声明为公用成员 hour; minute; ...
- asm.uew
/L16"ASM" Nocase Line Comment = ; File Extensions = ASM INC DEF /Colors = ,,,,, /Colors Ba ...
- socket基础示例(一)
//Socket基本编程 //服务端: using System.Net; using System.Net.Sockets; using System.Text; using System.Thre ...
- C# log Helper
using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; usin ...
- Best Time to Buy and Sell Stock I II III
Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a gi ...
- N-Queens 解答
Question The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no tw ...
- 转(havel 算法)
http://www.cnblogs.com/wally/p/3281361.html poj 1659(havel算法) 题目链接:http://poj.org/problem?id=1659 思路 ...
- Cocos2d-x 架构一个游戏的一般思路
采用下面的步骤来实现游戏逻辑: 通过应用程序代理类来初始化第一个CCScene(即AppDelegate里面的第一个CCScene), CCScene里面实例化一个或者多个CCLayer,并把它们当作 ...