Cable master(二分)

来源:互联网 发布:合泰单片机c语言教程 编辑:程序博客网 时间:2024/06/09 19:34
Cable master
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 43176
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.

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).

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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 淘宝买家投诉成立后怎么办 天猫投诉成立了怎么办 新开实体店铺没生意怎么办 新开淘宝没流量怎么办 白色板鞋有青草弄的绿色怎么办 淘宝租衣服不退押金怎么办 c盘不可以扩展怎么办 实践教学管理平台忘记账号怎么办 淘宝申请售后店家不处理怎么办 全民k歌地区限制怎么办 网络电视hdp无法下载怎么办 淘宝店铺销量为零怎么办 快递号填错卖家拒绝退款申请怎么办 淘宝店代购 售假怎么办 淘宝申请售后卖家没钱怎么办 淘宝禁止评价一个月怎么办 被卖家电话骚扰怎么办 恶意骚扰扣12分怎么办 新店开张交保证金被骗了怎么办 支付宝蚂蚁花呗逾期怎么办 被注销的微信怎么办 花呗有些不能用怎么办 实体店生意不好做怎么办 电器实体店生意越来越差怎么办 开业第一天不吉利怎么办 美容店开业第一天没人怎么办 淘宝店铺没有人访问怎么办 淘宝店铺没有人问怎么办 淘宝申请退款后店铺关闭怎么办 宝贝详情怎么改不了怎么办 改详情页后被删除宝贝怎么办 淘宝网商贷生意不好还不了怎么办 英国遗失在酒店物品怎么办 班福法则首位是0怎么办 同事能力比你强怎么办 新买的木板床响怎么办 笔记本键盘驱动坏了怎么办 云柜快递超时了怎么办 毕业设计被老师发现抄的怎么办 地板颜色太深了怎么办 皮质鞋子破皮了怎么办