poj---1064
来源:互联网 发布:巴丁算法集 编辑:程序博客网 时间:2024/06/07 17:51
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 118.027.434.575.39
Sample Output
2.00
这一题题意就是讲的是给你n个线段给你一个m然后让你求的最长在这n段中可以截取》=m段长度
这一个就是二分,之前没有理解题意,也没有什么算法,就是二分。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 11000
int a[N];
int main()
{
int n, m, i;
double l;
while(scanf("%d%d",&n,&m)!=EOF)
{
int Max = 0;
for(i=0; i<n; i++)
{
scanf("%lf", &l);
a[i]=l*100.0;
Max = max(Max, a[i]);
}
int low = 1, high = Max;
int res = 0;
while(low <= high)
{
int mid = (low + high)>>1;
int count = 0;
for(i=0;i<n;i++)
count+=a[i]/mid;
if(count>=m)
{
res=max(res, mid);
low=mid+1;
}
else
high=mid-1;
}
printf("%.2f\n", (double)res/100.0);
}
return 0;
}
- poj 1064
- POJ 1064
- POJ 1064
- poj-1064
- poj 1064
- poj---1064
- poj 1064
- POJ 1064
- POJ 1064
- POJ 1064
- 【POJ】1064
- poj 1064
- poj 1064 Cable master
- poj 1064 Cable master
- poj 1064 Cable master
- POJ 1064 Cable master
- 二分法 poj 1064
- poj 1064 Cable master
- Linux中的ls命令详细使用
- 整理 iOS 9 适配中出现的坑(图文)
- 【HDU】-5671-Matrix(思维,好)
- 手机号正则表达式详解和演示html页面代码 js、html
- HTML Iframe窗口在页面跳转
- poj---1064
- CodeForces 658A Bear and Reverse Radewoosh
- 使用phpstudy本地搭建织梦网站教程
- js 键盘事件
- C++中为什么要尽可能使用0而不是NULL
- 数组编译时出错error C2057: expected constant expression,以及解决办法
- springBoot集成mybatis
- ubuntu安装
- 查看硬盘UUID