POJ 1064 Cable master(初遇二分)
来源:互联网 发布:数据库建立流程图 编辑:程序博客网 时间:2024/05/17 04:04
题目链接:http://poj.org/problem?id=1064
题意:有n条绳子,他们的长度是Li,如果从他们中切割出K条长度相同的绳子,这相同的绳子每条有多长,输出至小数点后两位
“ then the output file must contain the single number "0.00" (without quotes).”不是四舍五入到两位,一般四舍五入题目会说“bounded to”的提示
显然想得到的绳子越短就越能得到,绳子太长就得不到,二分搜即可
//236K94MS#include<cstdio>#include<algorithm>#include<iostream>#include<cmath>using namespace std;int n,k;double a[10100];bool judge(double x){ int cnt=0; for(int i=1;i<=n;i++){ cnt+=a[i]/x; } return cnt>=k? 1:0;}int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) scanf("%lf",&a[i]); double lb=0,ub=100100; while(ub-lb>1e-5){ double mid=(lb+ub)/2; if(judge(mid)){ lb=mid; } else{ ub=mid; } } printf("%.2f\n",floor(ub*100)/100); return 0;}
0 0
- 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 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 【二分】
- [Project organization] some advices
- 游览 Nana 1.0
- JavaBean的使用
- string==NULL 和*str=='\0'的不同
- 关于spring3中初始化问题$EnhancerBySpringCGLIB$eff0996c@1651ab4
- POJ 1064 Cable master(初遇二分)
- FPGA,altera的opencl之学习疑问
- POJ 2456 Aggressive cows(二分)
- 冬令营第十四天
- web.xml配置
- JS (window.showModalDialog) 弹窗中值的获取方式!
- oracle中Where子句的条件顺序对性能的影响
- JBPM中流程变量和任务变量的区别
- 小型团队的测试该何去何从