Cable master(二分)
来源:互联网 发布:合泰单片机c语言教程 编辑:程序博客网 时间:2024/06/09 19:34
Cable master
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 43176
Accepted: 9250
Accepted: 9250
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
题解:题目大意,
有n条绳子,每条绳子有一个长度,如果从这些绳子中切割出K条长度相同的绳子,求这K条绳子的最长长度
答案精确至小数点后两位……
#include<cstdio>#include<cmath>#include<string>#include<cstring>#include<algorithm>#include<iostream>#include<cstdlib>#include<queue>#include<stack>#include<ctime>using namespace std;int x[10005];int n,m;bool check(int y) // 检查y是否符合题意{ int ans=0; for(int i=0; i<n; i++) ans+=x[i]/y; if(ans>=m)return true; else return false;}int main(){ scanf("%d%d",&n,&m); double a; int s=0; for(int i=0; i<n; i++) { scanf("%lf",&a); x[i]=(int)(a*100); // 转化为厘米(整数) 容易处理 s=max(s,x[i]); } int l=1,r=s,ans=0; while(l<=r) { int mid=(l+r)/2; if(check(mid)) { ans=mid; l=mid+1; } else r=mid-1; } printf("%.2f\n",ans/100.0); // 注意 坑点,隐性转换不能用lf 错了好多次……(额,刚刚又试了下,c++可以用lf和f都可以过,G++只能用f,可能是因为在G++上double和float不一样吧)}
0 0
- Cable master(二分)
- POJ1064:Cable master(二分)
- POJ1064 -- Cable master(二分)
- poj1064(二分)Cable master
- Cable master(二分查找)
- hdoj 1551 Cable master(二分)
- POJ - Cable master (二分搜索)
- poj-1064Cable master(二分)
- poj1064 Cable master(二分求解)
- POJ 1064 Cable master (二分答案)
- POJ1064 Cable master(二分搜索)
- POJ 1064 Cable master (二分搜索)
- HDOJ 1551 Cable master(二分)
- POJ 1064 Cable master(二分)
- POJ - 1064 Cable master(二分搜索)
- Cable master(浮点数二分)
- POJ 1064 Cable master(二分-精度)
- POJ1064 Cable master(二分查找)
- web前端-在迷惘中的探索HTML5(四)HTML5之拖动
- 漫漫人生路,何时是个始?
- Vue2.0 探索之路——生命周期和钩子函数的一些理解
- Centos下安装并配置ODBC连接MySQL 【转】
- 2384 字符串
- Cable master(二分)
- CassiniDev源码学习
- SurfaceView的工作原理
- 使用node.js创建应用
- Linux 下curl模拟Http 的get or post请求
- C风格字符串及常用库函数总结
- 团体程序设计天梯赛L1-017到底有多二
- HDOJ 1325 Is It A Tree?(并查集+入度判断)
- 刷cm14或lineage时提示错误7的解决办法