zoukankan      html  css  js  c++  java
  • 5971: Cable master(二分+卡精度)

    5971: Cable master 分享至QQ空间

    时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte
    总提交: 81            测试通过:20

    描述

     

    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.

    输入

     

    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.

    输出

     

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

    样例输入

     

    4 11
    8.02
    7.43
    4.57
    5.39

    样例输出

     2.00

    题目来源

    Northeastern Europe 2001

     

     

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 int n,m;
     5 const int maxn=1e4+5;
     6 double arr[maxn];
     7 
     8 bool check(double mid){
     9     int num=0;
    10     for(int i=1;i<=n;i++){
    11         num+=(int)(arr[i]/mid);
    12     }
    13     return num>=m;
    14 }
    15 
    16 int main(){
    17     double sum=0;
    18     scanf("%d%d",&n,&m);
    19     for(int i=1;i<=n;i++){
    20         scanf("%lf",&arr[i]);
    21         arr[i]+=0.005;
    22         sum+=arr[i];
    23     }
    24     double L=0.00,R=sum/m;
    25     double ans=-1,eps=1e-9;
    26     while(L+eps<R){
    27         double mid=(L+R)/2;
    28         if(check(mid)){
    29             L=mid,ans=mid;
    30         }
    31         else R=mid;
    32     }
    33     printf("%.2f
    ",floor(ans*100)/100);
    34     return 0;
    35 
    36 }
    View Code

     

     

  • 相关阅读:
    在AE中通过SDE添加图层(转)
    上一视图下一视图功能实现(C#+SuperMap Objects)
    [Python入门及进阶笔记]Python基础内置函数小结
    Javascript小球
    64位centos下安装python的PIL模块
    [Python入门及进阶笔记]Python基础集合小结
    C语言的那些小秘密之【链表(二)】
    巴斯卡三角形
    [Python入门及进阶笔记]Python基础数字处理相关模块
    C语言的那些小秘密之【链表(一)】
  • 原文地址:https://www.cnblogs.com/qq-1585047819/p/11924340.html
Copyright © 2011-2022 走看看