poj 1064 (二分+控制精度) && hdu 1551
链接:http://poj.org/problem?id=1064
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 23896 | Accepted: 5118 |
Description
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
Output
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的更多相关文章
- POJ 1064 (二分)
题目链接: http://poj.org/problem?id=1064 题目大意:一堆棍子可以截取,问要求最后给出K根等长棍子,求每根棍子的最大长度.保留2位小数.如果小于0.01,则输出0.00 ...
- poj 1064(二分答案)
传送门:Problem 1064 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有N条绳子,长度分别为 length[1,2,3,.. ...
- POJ 1064 Cable master(二分查找+精度)(神坑题)
POJ 1064 Cable master 一开始把 int C(double x) 里面写成了 int C(int x) ,莫名奇妙竟然过了样例,交了以后直接就wa. 后来发现又把二分查找的判断条 ...
- poj 1064 Cable master 判断一个解是否可行 浮点数二分
poj 1064 Cable master 判断一个解是否可行 浮点数二分 题目链接: http://poj.org/problem?id=1064 思路: 二分答案,floor函数防止四舍五入 代码 ...
- POJ 1064 1759 3484 3061 (二分搜索)
POJ 1064 题意 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长度相同的绳子的话,这K条绳子每条最长能有多长?答案保留小数点后2位. 思路 二分搜索.这里要注意精度问题,代码中有详细说 ...
- 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 ...
- POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流)
POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流) Description Yo ...
- POJ - 2018 二分+单调子段和
依然是学习分析方法的一道题 求一个长度为n的序列中的一个平均值最大且长度不小于L的子段,输出最大平均值 最值问题可二分,从而转变为判定性问题:是否存在长度大于等于L且平均值大于等于mid的字段和 每个 ...
- 二分搜索 POJ 1064 Cable master
题目传送门 /* 题意:n条绳子问切割k条长度相等的最长长度 二分搜索:搜索长度,判断能否有k条长度相等的绳子 */ #include <cstdio> #include <algo ...
随机推荐
- mysql主从同步及清除信息
主:reset master; 从:reset slave all; mysql主从配置: 1.MySQL主配置文件增加如下:default-storage-engine = innodbinnodb ...
- Java锁的种类
转载自:---->http://ifeve.com/java_lock_see/ Java锁的种类以及辨析锁作为并发共享数据,保证一致性的工具,在JAVA平台有多种实现(如 synchroniz ...
- shell获取目录下最新的文件,文件是以日期命名
如果你为每个文件按日期命名的格式都一致的话,那么 "ls -l" 命令列出的文件列表就是默认按文件名称(日期先后)排序的.那么最后一个就是最新的,文件名可以用以下方式获取.file ...
- JavaScript 网址
1. javascript 模板引擎 http://aui.github.io/artTemplate/
- php之上传类
<?php /** * Created by PhpStorm. * User: Administrator * Date: 2016/5/26 * Time: 20:29 */ class u ...
- jsp:和属性相关的方法,请求的转发,重定向
jsp中与属性相关的方法: 方法: void setAttribute(String name, Object o): 设置属性 Object getAttribute(String name):获取 ...
- js&jq 发送验证码倒计时
<input type="text" name='' id="btn"> //发送验证码倒计时var wait=30; function t ...
- Ahui Writes Word
Ahui Writes Word Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- 分组排序SQL
SELECT * FROM (SELECT columns,ROWNUM AS RN FROM (SELECT DISTINCT columns FROM table WHERE 1=1)) T WH ...
- c++ list, vector, map, set 区别与用法比较
http://blog.csdn.net/alex_xhl/article/details/37692297 List封装了链表,Vector封装了数组, list和vector得最主要的区别在于ve ...