https://vjudge.net/problem/POJ-1064

二分就相当于不停地折半试。

C++AC,G++WA不知为何,有人说C函数ans那里爆int了,改了之后也没什么用。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define INF 0x3f3f3f3f
typedef unsigned long long ll;
using namespace std;
int n, m;
double L[], sum=;
int C(double x)//x为每条边长度
{
int ans = ;
for(int i = ; i < n; i++){
ans += (int)(L[i]/x);
}
if(ans < m) return ;
return ;
}
int main()
{
cin >> n >> m;
for(int i = ; i < n; i++){
cin >> L[i];
sum += L[i];
}
sum = sum/m+;
double lb = , ub = sum;//ub也可以直接等于INF
for(int i = ; i < ; i++){
double mid = (lb+ub)/;
if(C(mid)){
lb = mid;
}
else ub = mid;
}
printf("%.2lf\n", floor(lb*)/); //只能这么写,floor不能换成int,总之这是一个精度坑
return ;
}

poj1064 Cable master(二分查找,精度)的更多相关文章

  1. poj1064 Cable master(二分)

    Cable master 求电缆的最大长度(二分法)   Description Inhabitants of the Wonderland have decided to hold a region ...

  2. [POJ] 1064 Cable master (二分查找)

    题目地址:http://poj.org/problem?id=1064 有N条绳子,它们的长度分别为Ai,如果从它们中切割出K条长度相同的绳子,这K条绳子每条最长能有多长. 二分绳子长度,然后验证即可 ...

  3. 二分法的应用:POJ1064 Cable master

    /* POJ1064 Cable master 时间限制: 1000MS 内存限制: 10000K 提交总数: 58217 接受: 12146 描述 Wonderland的居民已经决定举办地区性编程比 ...

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

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

  5. (poj)1064 Cable master 二分+精度

    题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...

  6. POJ 1064 Cable master (二分法+精度控制)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 65358   Accepted: 13453 De ...

  7. poj1064 Cable master

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

  8. POJ1064 Cable master 【二分找最大值】

    题目:题目太长了! https://vjudge.net/problem/POJ-1064 题意分析:给了你N根长度为小数形式的棍子,再给出了你需要分的棍子的数量K,但要求你这K根棍子的长度必须是一样 ...

  9. POJ1064 Cable master(二分 浮点误差)

    题目链接:传送门 题目大意: 给出n根长度为1-1e5的电线,想要从中切割出k段等长的部分(不可拼接),问这个k段等长的电线最长可以是多长(保留两位小数向下取整). 思路: 很裸的题意,二分答案即可. ...

随机推荐

  1. virtualenv and virtualenvwrapper

    virtualenv 1.下载virtualenv工具 通过物理环境的pip工具安装  清华 国内 pip3 install -i https://pypi.tuna.tsinghua.edu.cn/ ...

  2. MUI组件四:选择器、滚动条、单选框、区域滚动和轮播组件

    目录(?)[+]   1.picker(选择器) mui框架扩展了pipcker组件,可用于弹出选择器,在各平台上都有统一表现.poppicker和dtpicker是对picker的具体实现.*pop ...

  3. SQL Server数据库存储过程中拼接字符串注意的问题

    在SQL Server数据库中书写复杂的存储过程时,一般的做法是拼接字符串,最后使用EXEC sp_executesql '拼接的字符串' 查询出结果. 先看一段代码: -- ============ ...

  4. Java中String直接赋字符串和new String的区别(面试常考)

    摘取自:https://www.cnblogs.com/guozhenqiang/p/5633269.html 解析Java中的String对象的数据类型 1. String是一个对象.  因为对象的 ...

  5. HDU-1009的解题报告

    Hdu-1009 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1009 题意:Fatmouse准备M磅的猫食,准备与猫守卫仓库有他最爱吃的食品贸易,J ...

  6. HierarchicalClustering:编写HierarchicalClustering层次聚类算法—Jason niu

    from numpy import * class cluster_node: def __init__(self,vec,left=None,right=None,distance=0.0,id=N ...

  7. 00-JAVA语法基础--动手动脑

    1.运行EnumTest.java,并分析结果,得出结论. 其源代码以及运行结果截图如下: 枚举类型的常量以字符串的形式顺序储.源代码中s和t不是原始数据类型.getCLass():取得当前对象所属的 ...

  8. Cinema CodeForces - 670C (离散+排序)

    Moscow is hosting a major international conference, which is attended by n scientists from different ...

  9. soul

    mark,数据使用gzip加密,因为公司网络卡,明天后天看.

  10. 记录Ubuntu & Windows下安装PyV8

    https://blog.csdn.net/hanshileiai/article/details/51628173