POJ 1064 Cable master
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 37865 | Accepted: 8051 |
Description
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
Output
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;
}
POJ 1064 Cable master的更多相关文章
- 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: 29554 Accepted: 6247 Des ...
- [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: 65358 Accepted: 13453 De ...
- POJ 1064 Cable master (二分查找)
题目链接 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. ...
随机推荐
- Java注解全面解析
1.基本语法 注解定义看起来很像接口的定义.事实上,与其他任何接口一样,注解也将会编译成class文件. @Target(ElementType.Method) @Retention(Retentio ...
- 李洪强iOS开发之OC语言类的深入和分类
OC语言类的深入和分类 一.分类 (一)分类的基本知识 概念:Category 分类是OC特有的语言,依赖于类. 分类的作用:在不改变原来的类内容的基础上,为类增加一些方法. 添加一个分类: 文件 ...
- *[hackerrank]ACM ICPC Team
https://www.hackerrank.com/contests/w6/challenges/acm-icpc-team 这道题在contest的时候数据量改小过,原来的数据量需要进行优化才能过 ...
- [codility]CountDiv
https://codility.com/demo/take-sample-test/count_div 此题比较简单,是在O(1)时间里求区间[A,B]里面能被K整除的数字,那么就计算一下就能得到. ...
- SpringMVC学习总结(二)——DispatcherServlet详解
摘要: DispatcherServlet是前端控制器设计模式的实现,提供Spring Web MVC的集中访问点,而且负责职责的分派,而且与Spring IoC容器无缝集成,从而可以获得Spring ...
- s3cmd的安装与配置
安装包链接:http://files.cnblogs.com/files/litao0505/s3.rar 安装S3cmd1. tar -zxf s3cmd-1.0.0.tar.gz2. mv s3c ...
- sqlserver防止数据库挂马新尝试
想法不错,放着以后应该会有用 网站挂马非常让人头痛,每次的安全措施都是治标不治本,想找到根本原因,只能去分析你的程序源代码,由于很多网站不是一个程序员开发,很多的注入漏洞很难发现,曾经通过公共文件加入 ...
- 255. Verify Preorder Sequence in Binary Search Tree
题目: Given an array of numbers, verify whether it is the correct preorder traversal sequence of a bin ...
- 253. Meeting Rooms II
题目: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] ...
- java 调用 phantomjs
java 调用 phantomjs 2014-11-21 13:55 2034人阅读 评论(2) 收藏 举报 分类: phantomjs(2) 日前有采集需求,当我把所有的对应页面的链接都拿到手, ...