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. Heroku使用

    先要生成一个公钥,使用命令:$ ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save ...

  2. MySQL主从问题

    Mysql数据库主从心得整理      管理mysql主从有2年多了,管理过200多组mysql主从,几乎涉及到各个版本的主从,本博文属于总结性的,有一部分是摘自网络,大部分是根据自己管理的心得和经验 ...

  3. dede调用指定的多个栏目导航

    {dede:channelartlist row=' typeid='1,2这里输入多个指定的栏目ID' } <li><a href='{dede:field name='typeu ...

  4. 百度云观测优化建议解决方案:未设置max-age或expires

    网页的缓存是由 HTTP 消息头中的 “Cache-control” 来控制的,常见的取值有 private.no-cache.max-age.must-revalidate 等,默认为private ...

  5. Lua 学习笔记(一)

    Lua学习笔记 1.lua的优势 a.可扩张性     b.简单     c.高效率     d.和平台无关 2.注释 a.单行注释 --        b.多行注释 --[[  --]] 3.类型和 ...

  6. Hexo学习笔记--常用命令及部署步骤

    参考资料: Hexo搭建Github静态博客:http://www.cnblogs.com/zhcncn/p/4097881.htmlHexo:独立博客新玩法:http://www.aips.me/h ...

  7. ac automaton 专题

    hdu2222 模板题 hdu2825 在ac自动机上的状压dp hdu3247 在ac自动机上bfs poj2778 求长度为n,不包含给定的m个字符串的任何一个的字符串的个数 其实就是求长度为n的 ...

  8. ios如何判断键盘是否已经显示

    ios如何判断键盘是否已经显示   在群里看到有人问:ios如何判断键盘已经显示在界面上. 其实这个解决很简单: 写一个单例来管理键盘的状态. 这个单例在初始化方法init种监听2个事件,分别是 UI ...

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

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

  10. Eclipse调试时出现source not found的问题

    Eclipse中新加载了一个java项目,打断点debug时,Debug小窗口显示source not found,网搜找到了解决办法,在此记录一下. 原文地址:http://blog.csdn.ne ...