zoukankan      html  css  js  c++  java
  • 算法复习——猜数问题

      上面这道题的四个KC的分类范围的解题方法可以直接在龙凡的《一类猜数问题的研究》找到··为了版权问题我这里就不贴了···

      代码:

      

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cmath>
    #include<ctime>
    #include<cctype>
    #include<string>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    inline long long R(){
        char c;long long f=0;
        for(c=getchar();c<'0'||c>'9';c=getchar());
        for(;c<='9'&&c>='0';c=getchar())    f=f*10+c-'0';
        return f;
    }
    int T;
    long long n,k,c;
    long long f1=0,f2[80000][105],f3[505],f4[70000][105];
    int main()
    {
        T=R();
        while(T--){
            n=R(),k=R(),c=R();
            if(n==k&&c==0){
                f1=0;int tim=0;
                while(f1<n){
                    f1=2*f1+1;
                    tim++;
                }
                cout<<tim<<"
    ";
            }
            else if(c==0){
                bool flag=false;
                for(int i=1;;i++){
                    if(flag)  break;            
                    for(int j=1;j<=k;j++){
                        f2[i][j]=f2[i-1][j-1]+f2[i-1][j]+1;
                            if(f2[i][j]>=n){
                                cout<<i<<"
    ";flag=true;
                                break;
                            }
                    }
                }
            }    
            else if(n==k&&c!=0){
                for(int i=2;;i++){
                    f3[i]=f3[i-1]+f3[i-2]+1;
                    if(f3[i]>=n){
                        cout<<i<<"
    ";
                        break;
                    }
                }
            }
            else{
                bool flag=false;
                for(int i=2;;i++){
                    if(flag)    break;
                    for(int j=1;j<=k;j++){
                        if(j>1)f4[i][j]=max(f4[i-1][j-1]+f4[i-2][j],f4[i-2][j-2]+f4[i-1][j])+1;
                        else f4[i][j]=max(f4[i-1][j-1]+f4[i-2][j],f4[i-1][j])+1;
                        if(f4[i][j]>=n){
                            cout<<i<<endl;
                            flag=true;break;
                        }
                    }
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    WCF Server Console
    Restart IIS With Powershell
    RestartService (recursively)
    Copy Files
    Stopping and Starting Dependent Services
    多线程同步控制 ManualResetEvent AutoResetEvent MSDN
    DTD 简介
    Using Powershell to Copy Files to Remote Computers
    Starting and Stopping Services (IIS 6.0)
    java中的NAN和INFINITY
  • 原文地址:https://www.cnblogs.com/AseanA/p/7765384.html
Copyright © 2011-2022 走看看