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

Cable master
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 23896   Accepted: 5118

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

×××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
要注意控制精度,以及最后的舍入误差。
脑残犯了个基础的错误,
// sum+=(int)str[i]/x;
这样强制转型,就有问题了,应该把要转型的部分用括号括起来,两边都要
舍入误差在于,如果结果是1.0099999
应该输出1.00,而不是1.01
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h> #define eps 1e-6 double str[];
int n,k; int judge(double x)
{
int sum=;
for(int i=; i<n; i++)
{
sum+=(int)(str[i]/x);
}
return sum;
} int main()
{
int i,j;
while(scanf("%d%d",&n,&k)!=EOF)
{
double left=0.0,right,sum=0.0,maxx=0.0;
//ght=n/k;
for(i=; i<n; i++)
{
scanf("%lf",&str[i]);
//if(maxx < str[i])
// maxx = str[i];
//sum+=str[i];
maxx=maxx<str[i]?str[i]:maxx;
}
right=maxx;
while(right-left > eps)
{
double mid=(left+right)/2.0;
if(judge(mid) >= k )
left=mid;
else
right=mid;
}
int tmp=right * ;
double ans=(double)tmp * 0.01;
printf("%.2lf\n",ans);
}
return ;
}

poj 1064 (二分+控制精度) && hdu 1551的更多相关文章

  1. POJ 1064 (二分)

    题目链接: http://poj.org/problem?id=1064 题目大意:一堆棍子可以截取,问要求最后给出K根等长棍子,求每根棍子的最大长度.保留2位小数.如果小于0.01,则输出0.00 ...

  2. poj 1064(二分答案)

    传送门:Problem 1064 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有N条绳子,长度分别为 length[1,2,3,.. ...

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

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

  4. poj 1064 Cable master 判断一个解是否可行 浮点数二分

    poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...

  5. POJ 1064 1759 3484 3061 (二分搜索)

    POJ 1064 题意 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长度相同的绳子的话,这K条绳子每条最长能有多长?答案保留小数点后2位. 思路 二分搜索.这里要注意精度问题,代码中有详细说 ...

  6. POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划)

    POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划) Descri ...

  7. POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流)

    POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流) Description Yo ...

  8. POJ - 2018 二分+单调子段和

    依然是学习分析方法的一道题 求一个长度为n的序列中的一个平均值最大且长度不小于L的子段,输出最大平均值 最值问题可二分,从而转变为判定性问题:是否存在长度大于等于L且平均值大于等于mid的字段和 每个 ...

  9. 二分搜索 POJ 1064 Cable master

    题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algo ...

随机推荐

  1. 获取CPUID等

    unit CommonUnit; interface uses Windows, SysUtils, DateUtils; Const CPUVendorIDs: .. ] of string = ( ...

  2. PHP Deprecated: Comments starting with '#' are deprecated in *.ini 警告解决办法

    新装的ubuntu 10.04系统,使用新立得装的PHP,但是每次我在命令行下执行php脚本时都会出如下的警告信息: PHP Deprecated:  Comments starting with ' ...

  3. 如何获取各大平台的播放地址(获得优酷的m3u8播放地址)为例

    1.打开safari 2.在顶部(黑色小苹果)旁边,点击safari. 3.打开里面的 偏好设置. 4.在高级 中 找到 “在菜单栏中显示开发菜单” 并打勾. 5.关闭窗口后,可以发现safari 顶 ...

  4. fork和exec一起使用

    先预览一下工程的目录树: 实现的功能:master进程启动slave进程. 看看Makefile内容: all: master.out slave.out master.out: master.cpp ...

  5. 《深度探索C++对象模型》2

    第四章: function语意学 非静态成员函数: 名称的特殊处理: 静态成员函数由于缺乏this指针,因此差不多等于非成员函数: virtual table布局(单一继承): 单一继承下函数调用: ...

  6. java面试每日一题13

    题目:有一个分数数列2/1.3/2.5/3.8/5.13/8........求出这个数列的前20项之和.运行结果如下32.660263 public class Page80 { /** * * @p ...

  7. Python中的变量、引用、拷贝和作用域

    在Python中,变量是没有类型的,这和以往看到的大部分编辑语言都不一样.在使用变量的时候,不需要提前声明,只需要给这个变量赋值即可.但是,当用变量的时候,必须要给这个变量赋值:如果只写一个变量,而没 ...

  8. 【转】MYSQL入门学习之一:基本操作

    转载地址:http://www.2cto.com/database/201212/173868.html 1.登录数据库    www.2cto.com       命令:mysql -u usern ...

  9. AGPS 常见的两种定位模式

    SI 定位模式: 用户发起定位请求,辅助GPS 模块快速进行定位.时间在6秒-15秒之间. 这个方式能够有效的解决普通GPS 最快需要30秒时间获得卫星星历的搜星慢的问题,如果使用AGPS将通过中移动 ...

  10. javascript学习(二) DOM操作HTML

    一:DOM操作HTML JavaScript能够改变页面中所有的HTML元素 JavaScript能够改变页面中所有的HTML属性 JavaScript能够改变页面中所有的CSS样式 JavaScri ...