Cable master
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 35269   Accepted: 7513

Description

Inhabitants of the Wonderland have decided to hold a regional programming contest. The Judging Committee has volunteered and has promised to organize the most honest contest ever. It was decided to connect computers for the contestants using a "star" topology - i.e. connect them all to a single central hub. To organize a truly honest contest, the Head of the Judging Committee has decreed to place all contestants evenly around the hub on an equal distance from it.
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

The first line of the input file contains two integer numb ers N and K, separated by a space. N (1 = N = 10000) is the number of cables in the stock, and K (1 = K = 10000) is the number of requested pieces. The first line is followed by N lines with one number per line, that specify the length of each cable in the stock in meters. All cables are at least 1 meter and at most 100 kilometers in length. All lengths in the input file are written with a centimeter precision, with exactly two digits after a decimal point.

Output

Write to the output file the maximal length (in meters) of the pieces that Cable Master may cut from the cables in the stock to get the requested number of pieces. The number must be written with a centimeter precision, with exactly two digits after a decimal point.
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
题目大意:有n根电缆,你需要k条等同长度的电缆,最后得到的电缆长度最长是多少。
思路分析:初学二分,做这道题的时候感觉和之前做的一道题非常相似,以为可以轻松切掉,可是在做的时候还是出现了问题,
正确的思路应该是化为厘米,然后用整数二分,如果直接用小数二分最后会出现问题四舍五入,对于这些数据
4 2540
8.02
7.43
4.57
5.39 =>0.01 4 2542
8.02
7.43
4.57
5.39 =>0.00
化为整数进行处理则可以避免这些问题,另外要注意二分上下限,下限自然是0,而上限你可以用sum/k,也可以用a[n-1],当出现sum的时候,
就会超过int数据范围,要用__int64,如果用a[n-1]为上界就不需要开__int64了,再就是写函数时要判断是否有死循环,我就写错了,狂
TLE不止orz.
代码:
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
#include <cmath>
#define LL long long
using namespace std;
const int maxn=10000+100;
const double pi=acos(-1.0);
double a[maxn];
int b[maxn];
int n,k;
__int64 sum;
bool check(int x)
{
    int t=0;
   for(int i=0;i<n;i++)
   {
      int m=b[i];
      while(m>=x)
      {
          m-=x;
          t++;
        if(t>=k) return true;
      }
   }
   return  false;
}
int main()
{
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        sum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%lf",&a[i]);
            b[i]=a[i]*100;//将单位化为整数厘米
            sum+=b[i];
        }
        sort(b,b+n);
        int l=0,r=b[n-1];
        int  ans=0;
        while(l<=r)
        {
          int  mid=(l+r)/2;
          if(check(mid))  ans=mid,l=mid+1;
          else r=mid-1;
        }
         printf("%.2lf\n",ans*0.01);
    }
    return 0;
}

poj1064 二分,注意精度!的更多相关文章

  1. HDU 1007 Quoit Design(二分+浮点数精度控制)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

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

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

  3. UVA 10341 Solve It 解方程 二分查找+精度

    题意:给出一个式子以及里面的常量,求出范围为[0,1]的解,精度要求为小数点后4为. 二分暴力查找即可. e^(-n)可以用math.h里面的exp(-n)表示. 代码:(uva该题我老是出现Subm ...

  4. Cable master---poj1064(二分|卡精度)

    题目链接:http://poj.org/problem?id=1064 题意:有n条绳子,长度为Li,现在从这n条绳子中切割出K条相等的绳子,问切割出来的这k条绳子的最大长度为多少: 二分判断即可: ...

  5. POJ3111 K Best(另类背包+二分+变态精度)

    POJ3111 K Best,看讨论区说数据有点变态,精度要求较高,我就直接把循环写成了100次,6100ms过,(试了一下30,40都会wa,50是4000ms) 第一次在POJ上看到下面这种东西还 ...

  6. 【二分贪心+精度问题】F. Pie

    https://www.bnuoj.com/v3/contest_show.php?cid=9154#problem/F [题意] 给定n个已知半径的披萨,有m个人要分这n个披萨 要求每个人分到的面积 ...

  7. hdu.. 基础二分的精度问题

    #include<stdio.h>#include<iostream>using namespace std;double f(double x){ return 8*x*x* ...

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

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

  9. poj 3525 半平面交求多边形内切圆最大半径【半平面交】+【二分】

    <题目链接> 题目大意:给出一个四面环海的凸多边形岛屿,求出这个岛屿中的点到海的最远距离. 解题分析: 仔细思考就会发现,其实题目其实就是让我们求该凸多边形内内切圆的最大半径是多少.但是, ...

随机推荐

  1. effective条款15,在资源管理类中小心copying行为

    class A { private: int *p; void lock(){ cout << p << "is lock" << endl; ...

  2. 解决JavaScript中如何输出空格

    在写JS代码的时候,大家可以会发现这样现象:document.write("   1      2                3  ");结果: 1 2 3无论在输出的内容中什 ...

  3. 解决jQuery中美元符号($)命名与别的js脚本库引用冲突方法

    在Jquery中,$是JQuery的别名,所有使用$的地方也都可以使用JQuery来替换,如$('#msg')等同于JQuery('#msg') 的写法.然而,当我们引入多个js库后,在另外一个js库 ...

  4. Win7下部署 .NET MVC网站 之 HTTP错误 403.14-Forbidden 解决方法

    今天在 IIS 7 发布MVC 站点时 遇到 ”HTTP错误 403.14-Forbidden Web 服务器被配置为不列出此目录的内容 “ 的错误提示. 一番折腾后发现在web.config 中加入 ...

  5. vmware安装Linux时无法打开xpdf

    vmware10+redhat9 在装第二张镜像文件时,出现如下提示:无法打开xpdf-2.01-8软件包...... 解决方法: vmware中,虚拟机->设置->硬件->CD/D ...

  6. Python新手学习基础之函数-return语句与函数调用

    return语句 return语句的写法是: return 表达式 return语句用于退出函数,选择性地向调用方返回一个表达式.return在不带参数的情况下,默认返回None. None是一个特殊 ...

  7. arm get_vector_swi_address

    unsigned long* get_vector_swi_addr() { const void *swi_addr = 0xFFFF0008; unsigned ; unsigned ; unsi ...

  8. mysql安装图解 mysql图文安装教程(详细说明)-[转]

    很多朋友刚开始接触mysql数据库服务器,下面是网友整理的一篇mysql的安装教程,步骤明细也有详细的说明. MySQL5.0版本的安装图解教程是给新手学习的,当前mysql5.0.96是最新的稳定版 ...

  9. 枚举类:用enum关键字来定义一个枚举类

    1)枚举类的两种定义方法 1>通过构造器 public enum Grade{ A("A", "90-100"),B("B",&quo ...

  10. WPF中使用文件浏览对话框的几种方式

    原文:WPF中使用文件浏览对话框的几种方式 WPF本身并没有为我们提供文件浏览的控件, 也不能直接使用Forms中的控件,而文件浏览对话框又是我们最常用的控件之一. 下面是我实现的方式 方式1: 使用 ...