Cable master(hdu1551,二分查找)

Cable master 题解 浮点数的二分写的我难受,因此分享给大家一道题目 HDU1551:Cable master(二分) 题意:给出n条线段,以米的单位给出,小数点后两位(精确到厘米),要你对这些线段裁剪,裁剪出m条等长的线段,并且让这些线段尽可能长另外线段的长度不能小于1厘米,如果筹不够m条,输出0.00 下面是代码#include <iostream> #include <stdio.h> #include 阅读详情

http://acm.hdu.edu.cn/showproblem.php?pid=1551

Cable master

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1324    Accepted Submission(s): 491

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

Source

2001-2002 ACM Northeastern European Regional Programming Contest

Recommend

LL

 解析:

 题意:

 将n根网线切成k段相同长度的网线,问可切成的最长长度是多少;

 思路:

 利用二分发查找答案,每次偏右查找(因为要查找大的)

156MS 316K 978 B C++

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include <iostream>
using namespace std;
const int maxn=10010;
double a[maxn];
const double exp=1e-9;
int n,k;
int check(double m)
{   int t=0;
for(int i=0;i<n;i++)
{
t+=(int)(a[i]/m);
}
if(t>=k)
return 1;
else
return 0;
}
int main()
{
    int i,j;
    double ans,s;
    while(scanf("%d%d",&n,&k)!=EOF)
{
          if(n==0&&k==0)
            break;
            s=0.0;
            for(i=0;i<n;i++)
             {scanf("%lf",&a[i]);
              s+=a[i];
             }
            double l,r;
             double mid;
             ans=0.0;
             l=0;
             r=s;
             while(r-l>exp)//注意精度问题
             {   mid=(l+r)/2;
             	if(check(mid))
             	{
             	 ans=mid;
             	 l=mid;
             	}
             	else
             	r=mid;
             }
             printf("%.2lf\n",ans);
}
    return 0;
}


电价预测的Transformer实战:从注意力机制到超长序列建模 本文深入探讨了Transformer模型在电价预测领域的实战应用,对比了其与LSTM在处理长序列依赖和误差累积问题上的优劣。文章详细解析了自注意力机制的原理,并提供了处理超长序列的位置编码方法、构建专用预测模型的完整PyTorch代码,以及防止信息泄露的关键技巧。通过实战对比,展示了Transformer在并行计算、长距离建模和预测精度上的显著优势,并分享了应对极端波动和提升模型效率的高级优化策略。 阅读详情

相关推荐

AT91SAM9260搭建LINUX操作系统

一、 编写目的 2 二、 系统搭建 2 1. 下载相关软件包 2 2. Bootstrap编译 3 3. U-BOOT编译 5 4. LINUX编译 7 5. 通过U-BOOT的TFTP命令从TFTP服务器下载系统镜像 9 6. 文件系统制作 10 7. 挂载NFS作为根文件系统 10 三、 总结 14 一、编写目的 本文档用于记录AT91SAM9260 LINUX学

lshiceman的专栏 7424

HDU 1551(搜索题,二分)

Cable master<br />Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)<br />Total Submission(s): 257    Accepted Submission(s): 72<br /><br />Problem DescriptionInhabitants of the Wonderland have decided to hold a regional pr

-- bird -- 2378

Multisim仿真电路:(十二)MOS管缓启动电路设计与优化

本文详细介绍了基于Multisim的MOS管缓启动电路设计与优化方法。通过分析米勒平台效应,探讨RC参数选择、多级设计和有源电路等技巧,有效抑制冲击电流并优化开关损耗。文章结合仿真实例,提供实用的设计策略和实际应用注意事项,帮助工程师提升电源管理系统的可靠性。

pytorch8learner的博客 251

【HDU】-1551-Cable master(二分)

Cable master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3677    Accepted Submission(s): 1416 Problem Description Inhabitants o

Bear1998的博客 633

从零配置到稳定运行:A4988步进电机驱动模块的实战避坑指南

本文详细介绍了A4988步进电机驱动模块的配置与优化技巧,涵盖硬件连接、电流调节、微步设置及散热优化等关键环节。通过实战经验分享,帮助用户避开常见陷阱,实现步进电机的稳定运行,特别适合单片机开发者和3D打印机爱好者参考。

weixin_28452161的博客 190

从零到英雄:如何用FPGA和AD9288打造你的第一台便携式示波器

本文详细介绍了如何利用FPGA和AD9288 ADC芯片从零开始打造一台高性能便携式示波器。通过硬件架构设计、高速数据采集系统实现及信号处理与显示系统的开发,读者可以掌握400Msps采样率的实现方法,并了解关键器件选型与系统优化技巧。

jjj34的博客 285

HDU1551(二分)

Cable master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1247    Accepted Submission(s): 457 Problem Description Inhabitants of the

晓风残月xj 1115

英语语法-句法

摘要:本文系统梳理了英语句法知识,重点解析了五种基本句型及其扩展结构。内容包括句子类型(陈述句、疑问句、祈使句、感叹句)、复合句构成(从句分类与连词使用)、特殊句型(倒装、强调、引语转换)等。特别强调句子成分分析技巧,指出每种句子成分可由不同词法单元充当,需掌握成分识别与划分方法。文章还提供了往期语法系列链接,形成完整的英语语法学习体系,帮助读者建立从词法到句法的系统认知框架。

STCNXPARM的博客 8897

Poj 1064 && Hdu 1551 Cable master【二分搜索】

欢迎参加——每周六晚的BestCoder(有米!) Cable master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2548    Accepted Submission(s): 956 Pr

希望的专栏 771

AutoSAR配置视频讲解:新建DaVinci工程

AutoSAR实验视频讲解:闪烁一颗LED实验【新建DaVinci工程】 上一篇 | 下一篇 | 总目录 实验架构图 视频本频放在了文末,下图描述了本次实验配置内容在AutoSAR架构中的位置,供大家参考 实验内容 本节课程讲解新建DaVinci工程,听上去新建工程很简单,但是还是需要很多的准备工作和细节。主要内容是新建工程和导入dbc文件和导入arxml文件的方法 主要步骤 新建DaVinci工程 导入.dbc通信矩阵文件 导入Mcal的arxml文件 实验视频2:Mcal配置 提示:版权所在,违

雪云飞星的博客 6280

[低代码 + AI] 明道云与 Dify 的三种融合实践方式详解

融合方式技术路径优点局限或注意事项UI 嵌入iframe 表单嵌入快速集成、用户体验一致无法自定义交互逻辑明道云调用 DifyAPI 请求节点工作流自动化、逻辑灵活有 timeout 限制、需优化 promptDify 调用明道云插件或 API 调用节点可查询实际业务数据、增强 AI 智能需理解明道云 API 结构、权限设置复杂明道云与 Dify 的结合为低代码平台注入了智能动力。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 1195

HDU/HDOJ 1551 Cable master 2001-2002 ACM Northeastern European Regional Programming Contest

Cable master Time Limit : 2000/1000ms (Java/Other)Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 18Accepted Submission(s) : 11 Font:Times New Roman|Verdana|Georgia Fon...

lilisalo 190

YOLOv8改进 | 独家创新篇 | 给YOLOv8增加辅助可逆分支结构(PGI,1:1改进)(全网独家创新,附视频讲解)

这张图(图3)展示了可编程梯度信息(PGI)及其相关网络架构和方法。这种网络结构主要用于改进特征融合,以提高目标检测的性能。然而,由于信息瓶颈的存在,网络中可能会丢失一些信息。这是一种旨在减少信息丢失的网络设计。它通过可逆的列结构来尝试维持信息流通不受损失,但如图中“Heavy Cost”所示,这种结构会增加计算成本。c) 深度监督:这种方法通过在网络的多个层次中插入额外的监督信号来提高学习的效率和最终模型的性能。图中显示了通过深度监督连接的各个层。

Snu77的博客 3757

【二分查找合集01】从“找数字”到“找答案”:HDU 1551 Cable Master 详解

你有 NNN 根长短不一的网线(单位:米,精确到小数点后两位),现在需要从中切出 KKK 段等长的小段。这道题如果用暴力枚举长度,效率极低。但我们发现它满足 “单调性”:既然存在分界线,我们就可以在“可能的长度范围”内进行二分!在 HDU 提交这道题时,我踩了几个致命的坑,如果你也遇到了,请检查:HDU 题目要求读到 停止。计算机存储 有微小偏差(如 8.028.028.02 存为 8.019998.019998.01999)。直接用浮点数算会由于丢失精度导致 。累加段数 时,总数可能超过 上限,请

aqiu111111的博客 200

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

HDU 1551(Cable master)

基础题,二分查找即可。 #include <iostream> #include <iomanip> using namespace std; const int MAXN = 10005; const double eps = 1e-6; double len[MAXN]; //每段绳子的长度 int N, K; //判断是否能得到K段长为x的绳子 bool check(double x) { int total = 0; for (int i = 0; i <

Intelligence1028的博客 374

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

HDU 1551 Cable master(二分)

http://acm.hdu.edu.cn/showproblem.php?pid=1551

fcbruce 1061

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

二分查找

二分查找: 例题一: 题目来源:HDOJ-2199:Can you solve this equation? 题目大意:给出一个方程8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y,再给出一个Y,求出0~100之间的解。 题目分析:最基础的二分查找问题。 AC代码: #include #include double f(double x) {

apollo_miracle的博客 1263

HDU -1551 Cable master(二分)

Cable master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description Inhabitants of the Wonderland have decided to hold a regional programming conte...

名字太长容易被发现并打死 403

hdu 1551 Cable master

本题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1551 本题是给出电缆段数及每段长度,让求截出所给段数截得的每段的最大长度,AC代码: #include #include using namespace std; double a[10100]; int n,k; int F(double x) { int i; int su

暮光乐鱼的博客 415

HDU1551Cable 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

菜鸟的自我修养 407

hdu-1551 Cable master

Cable master Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total Submission(s) : 129   Accepted Submission(s) : 26 Problem Description Inhabitants of the Wonder

B_mess的博客 420

HDU1551 Cable master 二分

HDU1551 Cable master 二分

htrdchh的博客 220

【HDU】1551 - Cable master(二分)

点击打开题目 Cable master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3559    Accepted Submission(s): 1355 Problem Description

wyg1997 762

HDU - 1551 Cable master

问题描述: 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

m0_51727949的博客 161

HDU1551 Cable master(二分)

Cable master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2968    Accepted Submission(s): 1121 Problem Description Inhabitants of

KeyboardPianist的博客 488

HDU 1551 Cable master 二分

题意:把N条电缆截成相同的M段,问截成的最大长度是多少?思路:二分截的长度即可。(我不会告诉你我的程序样例都过不了) http://acm.hdu.edu.cn/showproblem.php?pid=1551 /********************************************* Problem : HDU 1551 Author : NMfloat

NM的专栏 397
上一篇: Wooden Sticks(hdu1051,LIS)
下一篇: Design T-Shirt(hdu1031,简单排序)
lrbj
博客等级 码龄14年 11粉丝 228原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值