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. Winform控件缩写

    控件名称 缩写 Buttom按钮 Btn CheckBox复选框 Chk ColumnHeader视图列表头 Col ComboBox组合框 Cbo ContextMenu快捷菜单 Ctm DataG ...

  2. php 之 注册审核(0523)

    当注册后,先将信息保存到session,通过审核后才会添加到数据库中, 审核通过后状态变为已通过,这时添加到数据库中的信息进行登录.若发现此用户的不良行为,可以撤销通过. 注册页面: <!DOC ...

  3. 用Ajax读取XML格式的数据

    ].firstChild.data);}catch(exception){ }}}}</script>

  4. iOS开发之动画编程的几种方法

    iOS开发之动画编程的几种方法 IOS中的动画总结来说有五种:UIView<block>,CAAnimation<CABasicAnimation,CATransition,CAKe ...

  5. 使用jcifs.smb.SmbFile读取Windows上共享目录的文件

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws Servl ...

  6. windows driver inf文件

    原来修改了inf文件会导致签名过的驱动包哈希值不正确了啊.现在才知道. = = http://www.chiphell.com/thread-827956-1-1.html

  7. Android文件下载(实现断点续传)

    本文将介绍在android平台下如何实现多线程下载,大家都知道,android平台使用java做为开发语言,所以java中支持的多线程下载方式在android平台下都支持,其中主要有两种方式可以实现多 ...

  8. linux tee 命令详解

    man tee: NAME tee - read from standard input and write to standard output and files SYNOPSIS tee [OP ...

  9. Linux企业级项目实践之网络爬虫(18)——队列处理

    所有的URL都接受管理,并在此进行流动.URL从管理模块的存储空间开始,一直到最后输出给磁盘上的URL索引,都由此部分调度.首先,给出URL调度的一般过程,如图所示.其流程的各个具体操作,后面详述.要 ...

  10. tyvj1185营业额统计

    描述 Description 营业额统计  Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况.  Tiger拿出了公司的账本,账本上记录了公司 ...