zoukankan      html  css  js  c++  java
  • UVA 10934 Dropping water balloons(装满水的气球)(dp)

    题意:有k个气球,n层楼,求出至少需要多少次实验能确定气球的硬度。气球不会被实验所“磨损”。

    分析:

    1、dp[i][j]表示第i个气球,测试j次所能确定的最高楼层。

    2、假设第i-1个气球测试j-1次所确定的最高楼层是a,

    若第i个气球在测试第一次的时候摔破了,那摔破所在的楼层b<=a+1---------dp[i - 1][j - 1] + 1。

    若没摔破,则前i-1个球在此楼层也不会摔破,也就是说当前至少有i个完好的球可以测试以及j-1次机会可以继续测试-------------dp[i][j - 1]。

    #pragma comment(linker, "/STACK:102400000, 102400000")
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define Min(a, b) ((a < b) ? a : b)
    #define Max(a, b) ((a < b) ? b : a)
    const double eps = 1e-8;
    inline int dcmp(double a, double b){
        if(fabs(a - b) < eps) return 0;
        return a > b ? 1 : -1;
    }
    typedef long long LL;
    typedef unsigned long long ULL;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
    const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const int MAXN = 100 + 10;
    const int MAXT = 10000 + 10;
    using namespace std;
    ULL dp[MAXN][MAXN];
    void init(){
        for(int i = 1; i < 64; ++i){
            for(int j = 1; j < 64; ++j){
                dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 1] + 1;
            }
        }
    }
    int main(){
        int k;
        ULL n;
        init();
        while(scanf("%d%llu", &k, &n) == 2){
            if(!k) return 0;
            k = Min(k, 63);//最多测试63次,所以最多需要63个气球
            bool ok = false;
            for(int i = 0; i <= 63; ++i){
                if(dp[k][i] >= n){
                    printf("%d\n", i);
                    ok = true;
                    break;
                }
            }
            if(!ok) printf("More than 63 trials needed.\n");
        }
        return 0;
    }
    

      

  • 相关阅读:
    java中a++和++a的区别详解
    Oracle 对比两张表不一样 的数据
    通配符的匹配很全面, 但无法找到元素 'tx:annotation-driven' 的声明
    Java语言基础-运算符
    java中+=详解 a+=b和a=a+b的区别
    java语言基础-变量
    java语言基础-进制
    Spring整合CXF发布及调用WebService
    Oracle Job定时任务的使用详解
    MySQL的主从配置
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6439957.html
Copyright © 2011-2022 走看看