poj 1064 Cable master 判断一个解是否可行 浮点数二分

题目链接:

http://poj.org/problem?id=1064

思路:

二分答案,floor函数防止四舍五入

代码:

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int maxn = 10005;
const double INF = 100005;
int n,k;
double len[maxn];
bool check(double x) {
int sum=0;
for(int i=0;i<n;++i) sum+=int(len[i]/x);
return sum>=k;
}
int main() {
scanf("%d %d",&n,&k);
for(int i=0;i<n;++i) scanf("%lf",&len[i]);
double l=0,r=INF;
for(int i=0;i<100;++i) {
double mid=(l+r)/2;
if(check(mid)) l=mid;
else r=mid;
}
printf("%.2f\n",floor(r*100)/100);//floor防止四舍五入
return 0;
}

poj 1064 Cable master 判断一个解是否可行 浮点数二分的更多相关文章

  1. POJ 1064 Cable master(二分查找+精度)(神坑题)

    POJ 1064 Cable master 一开始把 int C(double x) 里面写成了  int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...

  2. 二分搜索 POJ 1064 Cable master

    题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algo ...

  3. Poj:1064 : :Cable master (假定一个解并判断是否可行)(二分搜索答案)

    Description Inhabitants of the Wonderland have decided to hold a regional programming contest. The J ...

  4. [ACM] poj 1064 Cable master (二分查找)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21071   Accepted: 4542 Des ...

  5. [ACM] poj 1064 Cable master (二进制搜索)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21071   Accepted: 4542 Des ...

  6. POJ 1064 Cable master (二分查找)

    题目链接 Description Inhabitants of the Wonderland have decided to hold a regional programming contest. ...

  7. POJ 1064 Cable master (二分)

    题目链接: 传送门 Cable master Time Limit: 1000MS     Memory Limit: 65536K 题目描述 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长 ...

  8. POJ 1064 Cable master

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37865   Accepted: 8051 Des ...

  9. poj 1064 Cable master【浮点型二分查找】

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 29554   Accepted: 6247 Des ...

随机推荐

  1. java笔记02

    一,编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数 /** * */ package 课堂2; import java.util.Random; /** * @author 信16 ...

  2. win7与centos虚拟机的共享文件夹创建

    本文在win7环境下,在virtualbox5.0.16中的虚拟机centos6.7创建linux虚拟机与win7主机的共享文件夹. 首先点击virtualbox上"设置"按钮,在 ...

  3. Spring Cloud官方文档中文版-Spring Cloud Config(下)-客户端等

    官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#_serving_alternative_formats 文中例子我做了 ...

  4. Linux环境下网卡配置

    DEVICE=eth0 HWADDR=08:00:27:0D:3C:F6 TYPE=Ethernet UUID=73ff4482-1baf-4c9b-b859-720ca92a704a ONBOOT= ...

  5. windows 系统下C++实现的多线程

    摘抄http://blog.csdn.net/huyiyang2010/article/details/5809919 Thread.h #ifndef __THREAD_H__ #define __ ...

  6. You can Solve a Geometry Problem too(判断两线段是否相交)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  7. CI脚本异常退出问题定位

    背景 在CI脚本中,使用类似如下脚本进行项目编译的计时,但在执行过程中,有时会出现CI脚本(命名为ci.sh)未完全执行的情况: #!/bin/bash -e sleep_time=$1 start_ ...

  8. Android 开发笔记___RadioButton

    horizontal <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" and ...

  9. Problem D: 栈小游戏

    #include <iostream> #include <vector> #include <stack> #include <algorithm> ...

  10. linux tar命令 压缩、打包、解压 详解

    linux tar命令 压缩.打包.解压 详解 1.常用压缩命令 tar –czvf 压缩后的文件.tar.gz 要压缩的文件 2.常用解压命令 tar –xzvf 解压后的文件.tar.gz [要解 ...