zoukankan      html  css  js  c++  java
  • HDU 1551 Cable master【二分答案】

    题意:给出n块木板,它们分别的高度,现在要把它们裁切成k块,问裁切成的最大的高度

    二分答案,上限是这n块木板里面的最大值 然后每一个答案去判断一下是否满足能够裁切成k块

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<set>
     9 #include<queue> 
    10 #include<algorithm>  
    11 using namespace std;
    12 
    13 typedef long long LL;
    14 const int INF = (1<<30)-1;
    15 const int mod=1000000007;
    16 const int maxn=1000005;
    17 
    18 double a[maxn];
    19 int n,k;
    20 
    21 int ok(double x){
    22     int ans=0;
    23     for(int i=1;i<=n;i++){
    24         ans+=(int)(a[i]/x);
    25     }
    26     if(ans<k) return 0;
    27     return 1;
    28 }
    29 
    30 int main(){
    31     while(scanf("%d %d",&n,&k)!=EOF&&n&&k){
    32         double hmax=-1;
    33         for(int i=1;i<=n;i++) scanf("%lf",&a[i]),hmax=max(hmax,a[i]);
    34         
    35         double l=0.000,r=hmax;
    36         
    37         while(r-l > 1e-6){
    38             double mid=(l+r)/2;
    39             if(ok(mid)) l=mid;
    40             else r=mid;
    41         }
    42         printf("%.2lf
    ",l);    
    43     }
    44     return 0;
    45 }
    View Code
  • 相关阅读:
    代码示例_触摸屏驱动
    代码示例_中断下半部
    代码示例_mmap的实现
    代码示例_阻塞IO
    代码示例_LCD控制
    代码示例_平台总线
    驱动_I2c驱动框架
    驱动_Input输入子系统
    Windows切换桌面或窗口快捷键
    几何分布
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4541503.html
Copyright © 2011-2022 走看看