二分搜索 POJ 1064 Cable master
/*
题意:n条绳子问切割k条长度相等的最长长度
二分搜索:搜索长度,判断能否有k条长度相等的绳子
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
double w[MAXN];
int n, k; int check(double len) {
int ret = ;
for (int i=; i<=n; ++i) {
ret += (int) (w[i] / len);
}
return ret;
} int main(void) { //POJ 1064 Cable master
//freopen ("POJ_1064.in", "r", stdin); while (scanf ("%d%d", &n, &k) == ) {
for (int i=; i<=n; ++i) {
scanf ("%lf", &w[i]);
}
double l = , r = 1e9;
for (int i=; i<=; ++i) {
double mid = (l + r) / ;
if (check (mid) >= k) l = mid;
else r = mid;
}
printf ("%.2f\n", floor (l * ) / );
} return ;
}
二分搜索 POJ 1064 Cable master的更多相关文章
- POJ 1064 Cable master(二分查找+精度)(神坑题)
POJ 1064 Cable master 一开始把 int C(double x) 里面写成了 int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...
- poj 1064 Cable master 判断一个解是否可行 浮点数二分
poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...
- POJ 1064 Cable master (二分)
题目链接: 传送门 Cable master Time Limit: 1000MS Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...
- [ACM] poj 1064 Cable master (二分查找)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21071 Accepted: 4542 Des ...
- POJ 1064 Cable master
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37865 Accepted: 8051 Des ...
- poj 1064 Cable master【浮点型二分查找】
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29554 Accepted: 6247 Des ...
- [ACM] poj 1064 Cable master (二进制搜索)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21071 Accepted: 4542 Des ...
- POJ 1064 Cable master (二分法+精度控制)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65358 Accepted: 13453 De ...
- POJ 1064 Cable master (二分查找)
题目链接 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. ...
随机推荐
- Elasticsearch5.6搭建及拼音中文混合搜索实现
https://blog.csdn.net/UUfFO/article/details/78154499
- hdu - 1394 Minimum Inversion Number(线段树水题)
http://acm.hdu.edu.cn/showproblem.php?pid=1394 很基础的线段树. 先查询在更新,如果后面的数比前面的数小肯定会查询到前面已经更新过的值,这时候返回的sum ...
- Perfect Service UVA - 1218
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...
- SAP EP 设置Portal别名安全模式
Securing the Portal Alias Cookie Context We recommend that you set the portal alias cookie to be del ...
- SQL server 2008 添加,删除字段
添加,刪除字段 如果要在数据表中添加一个字段,应该如何表示呢?下面就为您介绍表添加字段的SQL语句的写法,希望可以让您对SQL语句有更深的认识. 通用式: alter table [表名] add [ ...
- RAD 极速应用开发 Spring ROO 入门样例
官网 http://projects.spring.io/spring-roo/ Spring ROO in action ...
- appium desktop
Appium-desktop 下载地址:https://github.com/appium/appium-desktop/releases 一般功能 这些能力跨越多个驱动因素. 仅限Android 这 ...
- 图像处理之基础---yuv420及其rgb,bayer, yuv, RGB的相互转换详解
YUV格式解析1(播放器——project2) 根据板卡api设计实现yuv420格式的视频播放器 打开*.mp4;*.264类型的文件,实现其播放. 使用的视频格式是YUV420格式 YUV格式 ...
- Servlet+JSP 原理
Servlet是用Java编写的Server端程序,与协议和平台无关,可移植行较强. Servlet在编辑时须要导入特定的Servlet API 的包,类似于普通Java程序的写法. Servlet採 ...
- ios32---线程的状态
// // ViewController.m // 04-了解-线程的状态 // // 创建线程是处于新建状态,start是就绪状态,会放入到可调度线程池里面(cpu看线程是否可以调用,是看线程是否在 ...