题意:给定 n 条绳子,它们的长度分别为 ai,现在要从这些绳子中切出 m 条长度相同的绳子,求最长是多少。

析:其中就是一个二分的水题,但是有一个坑,那么就是最后输出不能四舍五入,只能向下取整。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e4 + 10;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
double a[maxn]; bool judge(double mid){
int ans = 0;
for(int i = 0; i < n; ++i) ans += (int)(a[i] / mid);
return ans >= m;
} double solve(){
double l = 0, r = INF;
for(int i = 0; i < 100; ++i){
double mid = (l+r) / 2.0;
if(judge(mid)) l = mid;
else r = mid;
}
return floor(l*100) / 100;
} int main(){
while(scanf("%d %d", &n, &m) == 2){
for(int i = 0; i < n; ++i) scanf("%lf", a+i);
printf("%.2f\n", solve());
}
return 0;
}

POJ 1064 Cable master (二分)的更多相关文章

  1. POJ 1064 Cable master (二分答案)

    题目链接:http://poj.org/problem?id=1064 有n条绳子,长度分别是Li.问你要是从中切出m条长度相同的绳子,问你这m条绳子每条最长是多少. 二分答案,尤其注意精度问题.我觉 ...

  2. [POJ] 1064 Cable master (二分查找)

    题目地址:http://poj.org/problem?id=1064 有N条绳子,它们的长度分别为Ai,如果从它们中切割出K条长度相同的绳子,这K条绳子每条最长能有多长. 二分绳子长度,然后验证即可 ...

  3. poj 1064 Cable master 二分 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=1064 题解 二分即可 其实 对于输入与精度计算不是很在行 老是被卡精度 后来学习了一个函数 floor 向负无穷取整 才能ac 代码如下 ...

  4. POJ 1064 Cable master | 二分+精度

    题目: 给n个长度为l[i](浮点数)的绳子,要分成k份相同长度的 问最多多长 题解: 二分长度,控制循环次数来控制精度,输出也要控制精度<wa了好多次> #include<cstd ...

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

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

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

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

  7. 二分搜索 POJ 1064 Cable master

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

  8. (poj)1064 Cable master 二分+精度

    题目链接:http://poj.org/problem?id=1064 Description Inhabitants of the Wonderland have decided to hold a ...

  9. [ACM] poj 1064 Cable master (二分查找)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21071   Accepted: 4542 Des ...

随机推荐

  1. 使用Fiddler测试HTTP接口

    Fiddler下载地址:https://www.telerik.com/download/fiddler/fiddler4 在测试http接口前,为避免干扰,我们启用过滤器 然后运行过滤器设置 我们以 ...

  2. Wireshark学习笔记——怎样高速抓取HTTP数据包

    0.前言     在火狐浏览器和谷歌浏览器中能够很方便的调试network(抓取HTTP数据包),可是在360系列浏览器(兼容模式或IE标准模式)中抓取HTTP数据包就不那么那么方便了.尽管也可使用H ...

  3. 百度小程序转换微信小程序

    Python脚本,一键转换Github地址:https://github.com/DWmelon/py-transfer-BdToWx 运行条件 具备Python环境,可在命令行中使用Python命令 ...

  4. CALL FUNCTION 'BAPI_PO_CREATE1' 相关报错

    *&---------------------------------------------------------------------**& Report  ZQJ06*&am ...

  5. java基础语言 运算符

    /* ++,--运算符的使用: 单独使用: 放在操作数的前面和后面效果一样.(这种用法是我们比较常见的) 参与运算使用: 放在操作数的前面,先自增或者自减,然后再参与运算. 放在操作数的后面,先参与运 ...

  6. Java for LeetCode 120 Triangle

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  7. Java for LeetCode 090 Subsets II

    Given a collection of integers that might contain duplicates, nums, return all possible subsets. Not ...

  8. selector + drawable 多状态图形

    select_drawble.xml<?xml version="1.0" encoding="utf-8"?> <selector xmln ...

  9. Machine Learning No.7: Support Vector Machines

    1. SVM hypothsis 2. large margin classification 3. kernals and similarity if  f1 = 1; if x if far fr ...

  10. Eureka 集群

    集群搭建是在单节点基础上做的 单节点注册中心搭建-->https://www.cnblogs.com/chenglc/p/9561295.html 在单节点的基础上修改配置文件 bootstra ...