POJ 1064 Cable master (二分)
来源:互联网 发布:情义我心知 编辑:程序博客网 时间:2024/06/06 01:16
题目链接:http://poj.org/problem?id=1064
题意:N条绳子,长度分别为Li。若从中切割出K条长度相同的绳子,这K条绳子每条最长能有多长。
二分查找,下界为0上界为最大的L,答案不能四舍五入。
用C++可以过,G++WA。。。为什么。。。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define eps 1e-6using namespace std;int n, k;double L[10010];int check(double x) {int cnt = 0;int i;for(i = 0; i < n; i++) {cnt += int(L[i] / x);}if(cnt >= k) return 1;else return 0;}int main() {scanf("%d %d", &n, &k);int i;double maxl = 0;for(i = 0; i < n; i++) {scanf("%lf", L + i);maxl = max(maxl, L[i]);}double l = 0, r = maxl;while(r - l > eps) {double mid = (l + r) / 2;if(check(mid)) l = mid;else r = mid;}printf("%.2lf\n", floor(r * 100) / 100);return 0;}
0 0
- poj-1064Cable 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 1064Cable 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(二分)
- socket异步编程--libevent的使用
- 用户空间与内核的交互---IOCTL
- Chrome浏览器下小于12号字的解决方案
- 程序员相关网站收集
- 自定义控件-截屏当前界面
- POJ 1064 Cable master (二分)
- Gridview 点击修改布局
- 机器学习-车牌识别框架学习
- android 完美隐藏软键盘
- IOCTL函数用法
- Caffe学习笔记10:图像数据生成caffe需要的(laveldb和lmdb)数据文件
- java生成图片验证码
- 密码提示语
- windows中Python串口编程(一)