POJ 1064 (二分)
来源:互联网 发布:淘宝账户管理在哪里找 编辑:程序博客网 时间:2024/06/05 18:43
题目链接:http://poj.org/problem?id=1064
题意:
给出n个木棒的长度,需要获得m根长度相等的木棒,可以将木棒简短,问:可以得到的最长的木棍长度是多少?
思路:
直接二分求解吧,需要注意一下精度,题目要求保留两位小数,可以直接将数*100来控制精度。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespace std;const int INF=0x3f3f3f3f;const int maxn=10010;int T,n,m;int a[maxn];int main(){#ifndef ONLINE_JUDGEfreopen("test.in","r",stdin);freopen("test.out","w",stdout);#endifwhile(~scanf("%d%d",&n,&m)){int low=1,high=-1;double x;for(int i=0;i<n;i++){scanf("%lf",&x);a[i]=(int)(x*100);if(a[i]>high) high=a[i];}int ans=0;while(low<=high){int count=0;int mid=(low+high)/2;for(int i=0;i<n;i++){count+=a[i]/mid;}if(count<m){high=mid-1;}else if(count>=m){low=mid+1;ans=max(ans,mid);}}printf("%.2lf\n",(double)ans/100.0);}return 0;}
0 0
- POJ 1064(二分)
- POJ 1064 (二分)
- poj 1064(简单二分)
- 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 masters
- POJ 1064 Cable master (二分)
- POJ 1064 Cable master (二分)
- POJ 1064Cable master(二分查找)
- POJ 1064 Cable master(二分)
- poj 1064 二分
- poj 1064 二分
- poj 1064 高精度 二分
- POJ 1064 (二分)
- C++ list 使用方法
- IOS高级控件(一)
- centos6.5修改硬盘分区
- 安卓蓝牙入门二-------整合版本
- 编写扩展性更好的程序——里氏替换原则
- POJ 1064 (二分)
- IOS高级控件(二)
- struts的开发模式
- redis命令 - APPEND
- Codeforces 617A Elephant 【水题】
- GCD_AFTER
- 用Python Pandas处理亿级数据
- IOS高级控件(三)
- QLable的“超链接”形式