POJ1063Cable master(二分搜索)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 36288 | Accepted: 7743 |
Description
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
Output
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
- #include <iostream>
- #include <math.h>
- #include <iomanip>
- using namespace std;
- const int MAXN=;
- const double ESP=1.0e-6;
- int n,k;
- double cab[MAXN];
- double test(double l)
- {
- int s=;
- for(int i=;i<n;i++)
- {
- s+=(int)(cab[i]/l);
- }
- return s>=k;
- }
- int main()
- {
- while(cin>>n>>k)
- {
- for(int i=;i<n;i++)
- {
- cin>>cab[i];
- }
- double l=0.0;
- double r=100000000.0;
- while(fabs(r-l)>ESP)
- {
- double mid=(l+r)/;
- if(test(mid)) l=mid;
- else r=mid;
- }
- double res=floor(r*)/100.0;
- cout<<showpoint<<setprecision()<<fixed<<res<<endl;
- }
- return ;
- }
POJ1063Cable master(二分搜索)的更多相关文章
- Poj:1064 : :Cable master (假定一个解并判断是否可行)(二分搜索答案)
Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...
- 二分搜索 POJ 1064 Cable master
题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algo ...
- POJ 1064 Cable master (二分)
题目链接: 传送门 Cable master Time Limit: 1000MS Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...
- 不光是查找值! "二分搜索"
2018-11-14 18:14:15 二分搜索法,是通过不断缩小解的可能存在范围,从而求得问题最优解的方法.在程序设计竞赛中,经常会看到二分搜索法和其他算法相结合的题目.接下来,给大家介绍几种经典的 ...
- 二分搜索 - Binary Search
二分搜索是一种在有序数组中寻找目标值的经典方法,也就是说使用前提是『有序数组』.非常简单的题中『有序』特征非常明显,但更多时候可能需要我们自己去构造『有序数组』.下面我们从最基本的二分搜索开始逐步深入 ...
- C++分治策略实现二分搜索
问题描述: 给定已排好序的n个元素组成的数组,现要利用二分搜索算法判断特定元素x是否在该有序数组中. 细节须知: (1)由于可能需要对分治策略实现二分搜索的算法效率进行评估,故使用大量的随机数对算法进 ...
- 不光是查找值!"二分搜索"
从有序数组中查找某个值 问题描述:给定长度为n的单调不下降数列a0,…,an-1和一个数k,求满足ai≥k条件的最小的i.不存在则输出n. 限制条件:1≤n≤1060≤a0≤a1≤…≤an-1< ...
- xamarin MasterDetailPage点击Master时卡顿现象
在很多项目中经常会使用到MasterDetailPage的布局方式,而且一般做为主页面来开发,在开发中,发现一个并不算Bug的问题,但是却发生了,以此记录下来,方便大家探讨. 现象是这样的,我开发了一 ...
- backup3:master 数据库的备份和还原
在SQL Server 中,master 数据库记录系统级别的元数据,例如,logon accounts, endpoints, linked servers, and system configur ...
随机推荐
- JavaWeb Session
1. Session概述 1.1. 什么是Session Session一般译为会话,是解决Http协议的无状态问题的方案,可以将一次会话中的数据存储在服务器端的内存中,保证在下一次的会话中可以使用. ...
- juniper ssg 常用命令
netscreen juniper ssg操作命令 2013年4月10日 命令行下取得配置信息 get config 命令行下取得相应时间设置 get clock set vrout ...
- 网络最大流的(Edmond Karp)算法
容量网络:在有向图D=(V,A),指定一个点为发点,记作 s,指定另一个点为收点,记作 t,其余点叫作中间点.对于A的每条弧(Vi,Ai),都对应一个权数 C ≥0,称为弧(Vi , Ai)的容量,将 ...
- 【codevs1028】花店橱窗布置(费用流)
这几天刚学了费用流,找到了这道题来练一练手. 题目: 题目描述 Description 假设以最美观的方式布置花店的橱窗,有F束花,V个花瓶,我们用美学值(一个整数)表示每束花放入每个花瓶所产生的美学 ...
- java深入探究12-框架之Structs
注意每次修改配置文件后必须项目重启 Structs2=structs1+xwork Struct2框架预先实现了一些功能: 1.请求数据的封装:2.文件上传的功能3.对国际化功能的简化4.文件效验功能 ...
- shell基础之书写需要用到的小工具
一.简单介绍 下面介绍几个可能不太常用但是面试题经常会用用到的小工具: 命令:cut 作用:截取某一个字段 '-d' 后面跟分隔字符,把字段分割为若干个区间. '-c' 后面接的是第几个字符,也可以是 ...
- MySql基础学习-总纲
- SpringBoot- springboot集成Redis出现报错:No qualifying bean of type 'org.springframework.data.redis.connection.RedisConnectionFactory'
Springboot将accessToke写入Redisk 缓存,springboot集成Redis出现报错 No qualifying bean of type 'org.springframewo ...
- 使用struts碰到的错误
这种错误更有可能url中路径写错了. 而这种情况更有可能使struts.xml写错了.特别要注意action的属性值class的编写是否正确.
- if 条件判断 和 判断总结---shell脚本
本文主要介绍了Shell脚本IF条件判断和判断条件总结,本文先是给出了IF条件判断的语法,然后给出了常用的判断条件总结,需要的朋友可以参考下. 前言: 无论什么编程语言都离不开条件判断.SHELL也不 ...