Cable master(好题,二分)
Cable master
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2473 Accepted Submission(s): 922
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.
The input is ended by line containing two 0's.
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>
double m[];
int N;double sum,K;
double search(){int temp=;
double l=,r=sum/K,mid;
while(r-l>1e-){temp=;
mid=(l+r)/;
for(int i=;i<N;++i)temp+=(int)(m[i]/mid);//temp代表能裁剪成的数量。。。
if(temp>=K)l=mid;
else r=mid;
}
return mid;
}
int main(){
while(scanf("%d%lf",&N,&K),N||K){sum=;
for(int i=;i<N;++i)scanf("%lf",&m[i]),sum+=m[i];
printf("%.2lf\n",search());
}
return ;
}
poj ac:
#include<stdio.h>
double m[];
int N;double sum,K;
double search(){int temp=;
double l=,r=sum/K,mid;
while(r-l>1e-){temp=;
mid=(l+r)/;
for(int i=;i<N;++i)temp+=(int)(m[i]/mid);
if(temp>=K)l=mid;
else r=mid;
}
return r;
}
int main(){double d;double t;
while(~scanf("%d%lf",&N,&K)){sum=;
for(int i=;i<N;++i)scanf("%lf",&m[i]),sum+=m[i];
d=search();
/// t=100*d;printf("%d\n",t);
printf("%.2f\n",(int)(d*)/100.0);
}
return ;
}
Cable master(好题,二分)的更多相关文章
- poj 1064 Cable master【浮点型二分查找】
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29554 Accepted: 6247 Des ...
- Cable master poj1064(二分)
http://poj.org/problem?id=1064 题意:共有n段绳子,要求总共被分为k段.问在符合题意的前提下,每段长最大是多少? #include <iostream> #i ...
- Cable master(二分题 注意精度)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26596 Accepted: 5673 Des ...
- POJ 1064 Cable master(二分查找+精度)(神坑题)
POJ 1064 Cable master 一开始把 int C(double x) 里面写成了 int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...
- [ACM] poj 1064 Cable master (二分查找)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21071 Accepted: 4542 Des ...
- (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 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...
- POJ 1064 Cable master (二分查找)
题目链接 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. ...
- Cable master(二分-求可行解)
Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Commi ...
随机推荐
- WPF ICommand 用法
基础类,继承与ICommand接口 using System; using System.Collections.Generic; using System.Linq; using System.Te ...
- Eclipse 里的 Classpath Variables M2_REPO 无法修改(maven)
解决方法: 在C:\Documents and Settings\Administrator\.m2中放入setting.xml,并修改本地仓库为 <localRepository>D ...
- Java客户端Jedis的八种调用方式
redis是一个著名的key-value存储系统,而作为其官方推荐的java版客户端jedis也非常强大和稳定,支持事务.管道及有jedis自身实现的分布式. 在这里对jedis关于事务.管道和分 ...
- Java里多个Map的性能比較(TreeMap、HashMap、ConcurrentSkipListMap)
问题 比較Java原生的 1. TreeMap 2. HashMap 3. ConcurrentSkipListMap 3种Map的效率. 结果 模拟150W以内海量数据的插入和查找,通过添加和 ...
- Qt相关问题
1. Qt编译中的error: cannot find -lGL和 error: collect2: error: ld returned 1 exit status 一般见于新安装的系统,马上就直 ...
- html中把li前面的的小圆点换成小图片的方法
li { list-style: none; background: url(../img/li_dis.png) no-repeat left; padding-left: 20px; }
- FullCalendar 的学习笔记(一)
前一段时间,一个老项目需要新增一个小功能,日程表~ 于是网上找了下,发现FullCalendar这个控件还不错于是就拿来用了下,下面简单介绍下我的学习笔记. 首先就是了解下FullCalendar的A ...
- AJAX 控件集之TextBoxWatermark(水印文本框)控件
功能: 可以让TextBox控件初始化的时候拥有水印文字.属性: TargetControlID :要使用具有水印效果的TextBox控件ID. WatermarkCssCla ...
- 判断两个View的GRect是否相等
if (CGRectEqualToRect(self.view.frame, rect)) { // do some stuff }
- String 字符串相等比较