Cable master POJ - 1064
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段电缆,然后给出一个k代表要求从n段截取的段数
//然后让你从这n段电缆中截取等长度的电缆,问最大能截取的长度是多大
#include<string>
#include<stdio.h>
#include<iomanip>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,k;
int a[10005];
int judge(int x)
{
int sum=0;
for(int i=0; i<n; i++)
sum+=a[i]/x;
if(sum>=k) return 1;
else return 0;
}
int main()
{
while(~scanf("%d%d",&n,&k))
{
for(int i=0; i<n; i++)
{
double f;
scanf("%lf",&f);
a[i]=(int)(f*100);
}
sort(a,a+n);
int high=a[n-1],low=1;
while(low<=high)
{
int mid=(low+high)>>1;
if(judge(mid)) low=mid+1;
else high=mid-1;
}
cout<<fixed<<setprecision(2)<<(double)high/100.0<<endl;//fixed 和 setpriecision 连用可以控制输出
}
return 0;
}
Cable master POJ - 1064的更多相关文章
- Divide and Conquer:Cable Master(POJ 1064)
缆绳大师 题目大意,把若干线段分成K份,求最大能分多长 二分法模型,C(x)就是题干的意思,在while那里做下文章就可以了,因为这个题目没有要求长度是整数,所以我们要不断二分才行,一般50-100次 ...
- (poj)1064 Cable master 二分+精度
题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...
- POJ 1064 Cable master(二分查找+精度)(神坑题)
POJ 1064 Cable master 一开始把 int C(double x) 里面写成了 int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...
- poj 1064 Cable master 判断一个解是否可行 浮点数二分
poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...
- 二分搜索 POJ 1064 Cable master
题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algo ...
- 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 ...
- POJ 1064 Cable master
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37865 Accepted: 8051 Des ...
- poj 1064 Cable master【浮点型二分查找】
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29554 Accepted: 6247 Des ...
随机推荐
- Codeforces 620C EDU C.Pearls in a Row ( set + greed )
C. Pearls in a Row There are n pearls in a row. Let's enumerate them with integers from 1 to n from ...
- 【CodeForces】913 E. Logical Expression
[题目]E. Logical Expression [题意]令x=11110000(2),y=11001100(2),z=10101010(2),n次询问,每次要求用[与][或][非][括号]构成含至 ...
- 【CF343D】 Water Tree(树链剖分)
题目链接 树剖傻逼题,练练手好久没写树剖了. 查询忘记\(pushdown\)抓了好久虫.. 全文手写,一遍过... #include <cstdio> const int MAXN = ...
- CRF原理解读
概率有向图又称为贝叶斯网络,概率无向图又称为马尔科夫网络.具体地,他们的核心差异表现在如何求 ,即怎么表示 这个的联合概率. 概率图模型的优点: 提供了一个简单的方式将概率模型的结构可视化. 通过 ...
- oracle 归档模式、补充日志
1.归档模式: Oracle数据库有联机重做日志,这个日志是记录对数据库所做的修改,比如插入,删除,更新数据等,对这些操作都会记录在联机重做日志里.一般数据库至少要有2个联机重做日志组.当一个联机重做 ...
- 简单实现JS上传图片预览功能
HTML代码 <div class="upload"> <input type="button" class="btn" ...
- scikit-learn模块学习笔记(数据预处理模块preprocessing)
本篇文章主要简单介绍sklearn中的数据预处理preprocessing模块,它可以对数据进行标准化.preprocessing 模块提供了数据预处理函数和预处理类,预处理类主要是为了方便添加到pi ...
- HDU 4370 0 or 1(spfa+思维建图+计算最小环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4370 题目大意:有一个n*n的矩阵Cij(1<=i,j<=n),要找到矩阵Xij(i< ...
- js实现静态页面跳转传参
最近有个项目: 存静态web服务,一个新闻页面列表出所有新闻摘要信息,然后通过点击新闻详情访问到该新闻的详情页面: 新闻展示的页面通过ajax请求接口获取到新闻的摘要信息,预计想通过id的方式访问到新 ...
- Merge k Sorted Lists——分治与堆排序(需要好好看)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 1 ...