POJ 1064 Cable master【二分】
来源:互联网 发布:软件视频会议排名 编辑:程序博客网 时间:2024/05/21 10:23
Cable master
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 46202 Accepted: 9875
Description
Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to connect computers for the contestants using a "star" topology - i.e. connect them all to a single central hub. To organize a truly honest contest, the Head of the Judging Committee has decreed to place all contestants evenly around the hub on an equal distance from it.
To buy network cables, the Judging Committee has contacted a local network solutions provider with a request to sell for them a specified number of cables with equal lengths. The Judging Committee wants the cables to be as long as possible to sit contestants as far from each other as possible.
The Cable Master of the company was assigned to the task. He knows the length of each cable in the stock up to a centimeter,and he can cut them with a centimeter precision being told the length of the pieces he must cut. However, this time, the length is not known and the Cable Master is completely puzzled.
You are to help the Cable Master, by writing a program that will determine the maximal possible length of a cable piece that can be cut from the cables in the stock, to get the specified number of pieces.
To buy network cables, the Judging Committee has contacted a local network solutions provider with a request to sell for them a specified number of cables with equal lengths. The Judging Committee wants the cables to be as long as possible to sit contestants as far from each other as possible.
The Cable Master of the company was assigned to the task. He knows the length of each cable in the stock up to a centimeter,and he can cut them with a centimeter precision being told the length of the pieces he must cut. However, this time, the length is not known and the Cable Master is completely puzzled.
You are to help the Cable Master, by writing a program that will determine the maximal possible length of a cable piece that can be cut from the cables in the stock, to get the specified number of pieces.
Input
The first line of the input file contains two integer numb ers N and K, separated by a space. N (1 = N = 10000) is the number of cables in the stock, and K (1 = K = 10000) is the number of requested pieces. The first line is followed by N lines with one number per line, that specify the length of each cable in the stock in meters. All cables are at least 1 meter and at most 100 kilometers in length. All lengths in the input file are written with a centimeter precision, with exactly two digits after a decimal point.
Output
Write to the output file the maximal length (in meters) of the pieces that Cable Master may cut from the cables in the stock to get the requested number of pieces. The number must be written with a centimeter precision, with exactly two digits after a decimal point.
If it is not possible to cut the requested number of pieces each one being at least one centimeter long, then the output file must contain the single number "0.00" (without quotes).
If it is not possible to cut the requested number of pieces each one being at least one centimeter long, then the output file must contain the single number "0.00" (without quotes).
Sample Input
4 118.027.434.575.39
Sample Output
2.00
Source
Northeastern Europe 2001
Point:
1.floor()函数,其功能是“向下取整”,或者说“向下舍入”,即取不大于x的最大整数(与“四舍五入”不同,下取整是直接去掉小数部分)。
2.终止条件,100次循环可以达到10 -30的精度。
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<queue> #include<stack> #include<vector> #include<map> #include<algorithm> using namespace std; #define ll long long #define ms(a,b) memset(a,b,sizeof(a)) const int M=1e5+10; const int inf=0x3f3f3f3f; const int mod=1e9+7; double a[M]; int i,j,k,n,m;bool check(double mid){int sum=0;for(int i=0;i<n;i++)sum+=int(a[i]/mid);return sum>=k;}int main(){while(~scanf("%d%d",&n,&k)){for(int i=0;i<n;i++)scanf("%lf",&a[i]);double lb=0,ub=100000+1;for(int i=0;i<100;i++){double mid=(ub+lb)/2;if(check(mid))lb=mid;else ub=mid;}printf("%.2lf\n",floor(lb*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 浮点数二分
- poj 1064 Cable master 二分长度
- POJ 1064 Cable master 浮点数二分
- poj-1064Cable master(二分)
- poj 1064 Cable master ,二分 精度!!!
- POJ 1064 Cable master (二分答案)
- 高效能人士的七个习惯——习惯二以终为始
- C# SQLite通用读写操作方法
- csrf
- 浅谈mvp架构模式
- Codeforces 821D Okabe and City【思维建图+Dij+优先队列优化】好题~好题~
- POJ 1064 Cable master【二分】
- 如何用 Android Studio 导入开源项目以及常见错误的解决办法
- Run-Time Check Failure #3
- 深入浅出看流媒体前世今生,分分钟二逼变牛逼
- Android中退出app的另类姿势
- [HPUOJ] 1152: 棋盘变换 [搜索]
- AndroidStudio 2.2.3:编译C++文件、生成so文件及so文件使用
- 解决NestScrollView嵌套RecyclerView,RecyclerView抢焦点导致页面会自己滑动
- 字符串置换