HDU-1551-Cable master

简介: HDU-1551-Cable master





Cable master

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 183   Accepted Submission(s) : 34

Problem 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 11 8.02 7.43 4.57 5.39      

 


Sample Output

      2.00      


题目分析:

4 11  

8.02  

7.43  

4.57  

5.39

意思是有4段电缆 现在要把它分成11段 问最长的分发

正好 8.02 / 2 =4   7.43 / 2=3   4.57 / 2 =2   5.39/  2=2     4+3+2+2=11 段

就这个意思 那么这个 2.00 就要用二分查找来确定了    

#include<cstdio>
#include<cstring>
int n,m;
double a[10010];
bool f(double x)
{
    int i,sum=0;
    for(i=0;i<n;i++)
        sum+=(int)(a[i]/x);
    return sum>=m;
}// 此处是把每个输入的数据进行除以x   这个x就是要把每段分成的长度
int main()
{
    int i;
    scanf("%d%d",&n,&m);
        for(i=0;i<n;i++)
           scanf("%lf",&a[i]);
        double l=0,r=1001000,mid;//  题上说  x的长度可以是 0 ---100千米   此处所给数据都是米 所以  r  应写成米
        while(r-l>1e-8)
        {
            mid=(r+l)/2;
            if(f(mid))  l=mid;
            else  r=mid;
        }
        r=(int)(r*100)/100.0; // 二分的最终结果保留两位数可能是一个 小数  此处样例的结果就是  2.01  但是数据结果是 2   所以此处要处理一下
        printf("%.2f\n",r);
    return 0;
}


目录
相关文章
|
XML 人工智能 缓存
使用 Higress 快速构建 AI 应用
Higress 基于企业内外的丰富场景沉淀了众多面向 AI 的功能,推出了 AI 原生的 API 网关形态并且全部开源。
448 79
|
Go
第74/90步《番外篇》第4章 Go语言二:变量、逻辑控制与函数 第29课
今天学习《番外篇》第4章 Go语言二:变量、逻辑控制与函数 第29课 递归函数与闭包
154 0
|
监控 前端开发 Java
Spring Cloud构建微服务架构:分布式服务跟踪(入门)【Dalston版】
Spring Cloud构建微服务架构:分布式服务跟踪(入门)【Dalston版】
159 0
|
2天前
|
人工智能 运维 安全
|
4天前
|
SpringCloudAlibaba 负载均衡 Dubbo
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?
本文对比分析了SpringCloudAlibaba框架下Feign与Dubbo的服务调用性能及差异。Feign基于HTTP协议,使用简单,适合轻量级微服务架构;Dubbo采用RPC通信,性能更优,支持丰富的服务治理功能。通过实际测试,Dubbo在调用性能、负载均衡和服务发现方面表现更出色。两者各有适用场景,可根据项目需求灵活选择。
384 124
微服务架构下Feign和Dubbo的性能大比拼,到底鹿死谁手?
|
7天前
|
人工智能 JavaScript 测试技术
Qwen3-Coder入门教程|10分钟搞定安装配置
Qwen3-Coder 挑战赛简介:无论你是编程小白还是办公达人,都能通过本教程快速上手 Qwen-Code CLI,利用 AI 轻松实现代码编写、文档处理等任务。内容涵盖 API 配置、CLI 安装及多种实用案例,助你提升效率,体验智能编码的乐趣。
682 107
|
1天前
|
算法 Python
【轴承故障诊断】一种用于轴承故障诊断的稀疏贝叶斯学习(SBL),两种群稀疏学习算法来提取故障脉冲,第一种仅利用故障脉冲的群稀疏性,第二种则利用故障脉冲的额外周期性行为(Matlab代码实现)
【轴承故障诊断】一种用于轴承故障诊断的稀疏贝叶斯学习(SBL),两种群稀疏学习算法来提取故障脉冲,第一种仅利用故障脉冲的群稀疏性,第二种则利用故障脉冲的额外周期性行为(Matlab代码实现)
221 152
|
3天前
|
Java 数据库 数据安全/隐私保护
Spring 微服务和多租户:处理多个客户端
本文介绍了如何在 Spring Boot 微服务架构中实现多租户。多租户允许单个应用实例为多个客户提供独立服务,尤其适用于 SaaS 应用。文章探讨了多租户的类型、优势与挑战,并详细说明了如何通过 Spring Boot 的灵活配置实现租户隔离、动态租户管理及数据源路由,同时确保数据安全与系统可扩展性。结合微服务的优势,开发者可以构建高效、可维护的多租户系统。
200 127