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 网关形态并且全部开源。
506 88
|
Go
第74/90步《番外篇》第4章 Go语言二:变量、逻辑控制与函数 第29课
今天学习《番外篇》第4章 Go语言二:变量、逻辑控制与函数 第29课 递归函数与闭包
160 0
|
监控 前端开发 Java
Spring Cloud构建微服务架构:分布式服务跟踪(入门)【Dalston版】
Spring Cloud构建微服务架构:分布式服务跟踪(入门)【Dalston版】
160 0
|
3天前
|
存储 关系型数据库 分布式数据库
PostgreSQL 18 发布,快来 PolarDB 尝鲜!
PostgreSQL 18 发布,PolarDB for PostgreSQL 全面兼容。新版本支持异步I/O、UUIDv7、虚拟生成列、逻辑复制增强及OAuth认证,显著提升性能与安全。PolarDB-PG 18 支持存算分离架构,融合海量弹性存储与极致计算性能,搭配丰富插件生态,为企业提供高效、稳定、灵活的云数据库解决方案,助力企业数字化转型如虎添翼!
|
14天前
|
弹性计算 关系型数据库 微服务
基于 Docker 与 Kubernetes(K3s)的微服务:阿里云生产环境扩容实践
在微服务架构中,如何实现“稳定扩容”与“成本可控”是企业面临的核心挑战。本文结合 Python FastAPI 微服务实战,详解如何基于阿里云基础设施,利用 Docker 封装服务、K3s 实现容器编排,构建生产级微服务架构。内容涵盖容器构建、集群部署、自动扩缩容、可观测性等关键环节,适配阿里云资源特性与服务生态,助力企业打造低成本、高可靠、易扩展的微服务解决方案。
1305 5
|
13天前
|
机器学习/深度学习 人工智能 前端开发
通义DeepResearch全面开源!同步分享可落地的高阶Agent构建方法论
通义研究团队开源发布通义 DeepResearch —— 首个在性能上可与 OpenAI DeepResearch 相媲美、并在多项权威基准测试中取得领先表现的全开源 Web Agent。
1332 87
|
2天前
|
弹性计算 安全 数据安全/隐私保护
2025年阿里云域名备案流程(新手图文详细流程)
本文图文详解阿里云账号注册、服务器租赁、域名购买及备案全流程,涵盖企业实名认证、信息模板创建、域名备案提交与管局审核等关键步骤,助您快速完成网站上线前的准备工作。
184 82
2025年阿里云域名备案流程(新手图文详细流程)