POJ
来源:互联网 发布:java培训学校 编辑:程序博客网 时间:2024/06/06 01:04
题意:给出n,m,给出n个电缆,求出满足电缆分割后满足m个的电缆的最大长度
思路:二分分割后的电缆长度,二分时 计算出在当前分割电缆长度下可以有多少个电缆
include <iostream>#include <cstdio>#include <algorithm>#include <set>#include <string>#include <cstring>#include <cmath>using namespace std;typedef long long ll;int n,k;double s[10005];bool cal(double x){ int ans=0; for(int i=1; i<=n; i++) { ans+=(int)(s[i]/x); if(ans>=k) return true; } return false;}int main(){ scanf("%d%d",&n,&k); double l=0,r=0,mid; for(int i=1; i<=n; i++) { scanf("%lf",&s[i]); r=max(r,s[i]); } while(r-l>1e-6) { mid=(l+r)/2.0; if(cal(mid)) l=mid; else r=mid; } printf("%.2lf\n",int(r*100)*0.01); return 0;}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- 蛇 形 填 数
- Proteus 8086 简单I/O读写实验
- JavaScript的cookie
- 林轩田之机器学习课程笔记(why can machines learn之theory of generalization)(32之6)
- MySQL —— 数据库,数据表的创建,修改,删除
- POJ
- 数据结构实验之排序七:选课名单
- 外观模式浅析
- [BZOJ1145][CTSC2008]图腾totem 树状数组
- 雇员管理系统-SSH版(九)
- 拓扑排序
- 安卓开发之计算结果保留两位有效数字(四舍五入)
- Nodepad++和编程
- numpy学习笔记