poj1064 Cable master(二分)

Cable master 求电缆的最大长度(二分法)

 

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 input consists of several testcases. The first line of each testcase contains two integer numbers 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 centimeter and at most 100 kilometers in length. All lengths in the input are written with a centimeter precision, with exactly two digits after a decimal point. 

The input is ended by line containing two 0's. 
 

Output

For each testcase write to the output 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 must contain the single number "0.00" (without quotes). 
 

Sample Input

4 11
8.02
7.43
4.57
5.39
0 0
 

Sample Output

2.00
 
题意:有N条绳子,他们的长度分别是Li。如果从他们中切割出K条长度相同的绳子的话,这K条绳子每条最长能有多长?答案保留2位小数。(例题)

题解 
    也就是求一个x ,   l1/ x +l2/x +l3/x +.....=K,求最大的x。求的过程中中间值x ,如果>=k也时 ,要求最大的x.
    条件C(x)=可以得到K条长度为x的绳子
    区间l=0,r等于无穷大,二分,判断是否符合c(x) C(x)=(floor(Li/x)的总和大于或等于K
 
输入电缆的个数n,和要分的份数k,求出所有电缆的长度和sum,在区间[0,sum/k]内用二分法求出最大的长度。
 
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<math.h>
using namespace std;
#define st 1e-8//10^-8
double a[10010];
int k, n;
int f(double x)
{
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        cnt += (int)(a[i] / x);  //括号不能少 
    }
    return cnt;
}
int main()
{

    double sum;
    scanf("%d%d", &n, &k);
    sum = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%lf", &a[i]);
        sum += a[i];
    }
    sum = sum / k;//平均值一定会比最终取得长度大
    double l = 0, r = sum, mid;
    while (fabs(l - r)>st)//控制精度
    {
        mid = (l + r) / 2;
        if (f(mid) >= k)//不断逼近,找到可以满足切割数量下的最大长度
            l = mid;
        else
            r = mid;
    }
    r=r*100;
    printf("%.2f\n", floor(r)/100);//向下取整
}
// 4 2542
// 8.02
// 7.43
// 4.57
// 5.39
// 0.00

 

转载于:https://www.cnblogs.com/-citywall123/p/9517626.html

### 关于 JetBrains IDEA 安装失败的解决方案 当遇到 JetBrains IDEA 安装失败的情况时,可以从多个方面排查并解决问题。以下是详细的处理方法: #### 1. 检查系统环境配置 确保操作系统满足 JetBrains IDEA 的最低运行要求。对于 Windows 用户来说,建议使用 Windows 7 或更高版本;MacOS 则需至少为 macOS Mojave (10.14) 及以上版本;Linux 发行版应具备较新的内核和支持库。 #### 2. 清理旧版本残留文件 如果之前尝试过安装或卸载过其他版本的 IntelliJ IDEA,则可能存在一些未完全清除掉的相关设置项或是临时文件夹影响新版本正常部署。可以手动删除 `~/.IntelliJIdea<version>` 和 `%USERPROFILE%\.IntelliJIdea<version>` 这样的目录来清理这些遗留物[^1]。 #### 3. 验证下载包完整性 有时由于网络原因或其他因素造成所获取到的应用程序压缩包损坏,在这种情况下即使解压后也无法成功启动应用程序。因此应当重新从官方渠道下载最新稳定发布的 .dmg / .exe 文件,并通过校验其哈希值确认无误后再继续下一步操作。 #### 4. 修改防火墙/杀毒软件规则 部分安全防护工具可能会阻止 IDE 执行必要的初始化动作而致使整个过程中断。暂时关闭实时保护机制或将该执行档加入白名单列表里通常能有效规避此类干扰现象的发生。 #### 5. 调整 Java 环境变量设定 作为基于 JVM 构建的产品之一,IDEA 对本地已安装 JDK 版本有着严格的要求。务必保证当前机器上存在兼容的目标平台解释器实例,并将其路径正确添加至全局 PATH 中以便调用[^2]。 #### 6. 尝试离线模式激活 针对某些特殊场景下可能出现授权验证环节超时等问题,可考虑切换成无需联网即可完成注册流程的方式——即利用许可证密钥实现永久解锁功能。具体做法是在首次引导界面选择 "Activate" -> 输入有效的序列号信息完成绑定手续[^3]。 ```bash # Linux/Mac 下查看 JAVA_HOME 是否指向合适位置 echo $JAVA_HOME ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值