POJ 1064 Cable master
来源:互联网 发布:隐藏php版本 编辑:程序博客网 时间:2024/05/20 05:44
有n条绳子,每条长度为Li,求切割出k条长度相同的绳子的最长长度有n条绳子,每条长度为Li,求切割出k条长度相同的绳子的最长长度
#include <stdio.h>#include <math.h>#define MAXN 10240#define INF 102400int n, k;double num[MAXN];bool Judge (double x) {//求绳长为x的情况下可得到的绳子条数是否比要求的多int sum = 0;for (int i = 0; i < n; i ++) {sum += floor(num[i]/x);//floor(x)求小于或等于x的最大整数}return sum >= k;}int main () {//freopen ("in.txt", "r", stdin);while (~scanf ("%d%d", &n, &k)) {double max = INF;for (int i = 0; i < n; i ++) {scanf ("%lf", &num[i]);max = max > num[i] ? max : num[i];//寻找最大绳长,也是切割任意条数下所能截得得最大绳长}double start = 0, mid, end = max;for (int i = 0; i < 100; i ++) {mid = (start + end)/2;if (Judge(mid))start = mid;elseend = mid;}printf ("%.2lf\n", floor(end*100)/100);//去除小数点第二位后的数字,防止四舍五入}return 0;}
0 0
- poj 1064 Cable master
- poj 1064 Cable master
- poj 1064 Cable master
- POJ 1064 Cable master
- poj 1064 Cable master
- POJ-1064-Cable master
- poj 1064--Cable master
- POJ 1064 Cable master
- POJ 1064 Cable master
- poj 1064 Cable master
- poj 1064 Cable master
- POJ(1064)cable master
- POJ 1064 Cable master
- cable master POJ 1064
- POJ 1064 Cable master
- POJ 1064 Cable Master
- POJ-1064 Cable master
- POJ 1064 Cable master
- Ogre 中级教程六
- utf8 mb4
- HDOJ 3047 Zjnu Stadium 并查集
- 安卓左右滑动的实例
- apk 反编译与预防
- POJ 1064 Cable master
- 非归档,os层面删除ogg数据文件后drop tablespace
- 【网站性能监测系统网络安全必修课 良好意识习惯必不可少】
- Spring中ApplicationContext加载机制和配置初始化
- 运行时之关联对象
- mini2440 dm9000 网卡驱动详解 2
- HDOJ 3038 How Many Answers Are Wrong 并查集
- springMVC+Quartz+mybatis+mysql+DWZ可视化定时器控制-stepOne
- 一个高性能分布式内存队列系统