题目链接:http://poj.org/problem?id=1064

题意:有n条绳子,长度为Li,现在从这n条绳子中切割出K条相等的绳子,问切割出来的这k条绳子的最大长度为多少;

二分判断即可;

但是本题的精度让人恶心;

#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#include<math.h>
using namespace std;
#define INF 0x3f3f3f3f
#define N 100550
#define PI 4*atan(1.0)
#define mod 10119
#define met(a, b) memset(a, b, sizeof(a))
typedef long long LL; int n, K;
double a[N]; bool Judge(double Mid)
{
int sum = ;
for(int i=; i<=n; i++)
sum += (int)(a[i]/Mid);
return sum>=K;
} int main()
{
while(scanf("%d %d", &n, &K)!=EOF)
{
for(int i=; i<=n; i++)
scanf("%lf", &a[i]); sort(a+, a+n+); double L = , R = a[n], ans = a[n]; while(R-L > 1e-)
{
double Mid = (L+R)/;
if(Judge(Mid))
L = Mid;
else
R = Mid;
}
printf("%.2f\n", floor(R*)/);///L会错;
}
return ;
}

Cable master---poj1064(二分|卡精度)的更多相关文章

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

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

  2. poj1064 Cable master(二分查找,精度)

    https://vjudge.net/problem/POJ-1064 二分就相当于不停地折半试. C++AC,G++WA不知为何,有人说C函数ans那里爆int了,改了之后也没什么用. #inclu ...

  3. Cable master(二分题 注意精度)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26596   Accepted: 5673 Des ...

  4. 【POJ - 1064】Cable master(二分)

    Cable master Descriptions 输入2个数 N  K n条绳子    要分成大于等于k段 求每段最长多长呢?并且每段不能小于1cm 必须以厘米精度写入数字,小数点后正好是两位数.如 ...

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

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

  6. Cable master(二分-求可行解)

    Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Commi ...

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

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

  8. POJ 1064 Cable master (二分)

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

  9. poj 1064 Cable master ,二分 精度!!!

    给出n根绳子,求把它们分割成K条等长的绳子的最大长度是多少? 二分 用 for(int i=0; i<100; ++i) 取代   while(r-l>eps) 循环100次精度能达到1e ...

随机推荐

  1. html主要笔记

    1.用title属性作为工具提示 2.链接到锚点 <a href="http://wickedlysmart.com/buzz#Coffee"> 3.<em> ...

  2. linux shell 随机字符生成单词

    #!/bin/sh #生成随机5个单词 filecount= wordcount= flag= #-lt -le -gt -ge -eq #while [ $f -lt $filecount ]; # ...

  3. iOS 动画效果:Core Animation & Facebook's pop

    本文转载至 http://www.cocoachina.com/ios/20151223/14739.html 感谢原创作者分享 前言相信很多人对实现 iOS 中的动画效果都特别头疼,往往懒得动手,功 ...

  4. c++ 纯虚析构函数

    ; 这就是一个纯虚析构函数,这种定义是允许的. 一般纯虚函数都不允许有实体,但是因为析构一个类的过程中会把所有的父类全析构了,所以每个类必有一个析构函数. 所以.纯虚析构函数需要提供函数的实现,而一般 ...

  5. word2010没有“标题2、标题3”样式的解决办法

    word2010没有“标题2.标题3”样式的解决办法 很多人用word的时候都喜欢用“标题1”“标题2”等样式来定义他们的文档标题,被这样定义的标题会出现在导航窗格中,使浏览起来非常方便.但是最近我发 ...

  6. Android Studio 调试系列之分析堆栈调用

    Analyze a Stack Trace 方法:Thread.dumpStack() 一 代码中添加Thread.dumpStack() 二 Android  Studio查看堆栈log 三 借助A ...

  7. Elasticsearch学习之嵌套聚合,下钻分析,聚合分析

    1. 计算每个tag下的商品数量 GET /ecommerce/product/_search { "aggs": { "group_by_tags": { & ...

  8. minix中atoi、atol、atof的实现

    在minix2.0源代码中,有将字符串类型转换为int.long.double类型的函数实现,相关的实现函数分别在atoi.c.atol.c.atof.c文件中,我们来逐一学习其中的源码: 1.int ...

  9. JavaAgent 应用(spring-loaded 热部署)

    上一篇文章简单介绍了 javaagent ,想了解的可以移步 “JavaAgent” 本文重点说一下,JavaAgent 能给我们带来什么? 自己实现一个 JavaAgent xxxxxx 基于 Ja ...

  10. centos7下安装nmon后,无法运行,提示 cannot execute binary file或/lib64/ld64.so.1不存在

    在centos 7.1上安装nmon后,从管网(http://nmon.sourceforge.net/pmwiki.php?n=Site.Download)下载tar包解压后,两台机器一台提示 ca ...