zoukankan      html  css  js  c++  java
  • H. Hard math problem



    H. Hard math problem

    Time Limit: 2000ms
    Case Time Limit: 2000ms
    Memory Limit: 65536KB
    64-bit integer IO format: %lld      Java class name: Main
    Font Size:  
        Xioumu was trapped by a mathematical puzzle recently.
     
        He wrote the number 0,1,2 on the blackboard, and then he does lots of operations on them, in each operation, he took out the larger two numbers of the three every time, added the two numbers and wrote down the sum on the blackboard, and then wiped any one of the original three numbers. He needed to use a minimum times of operations to get a maximum number x. Now he needs your help. 

    Input

        The first line is an integer T indicates the number of test cases.

        Input contains several test cases. 

        For each test case, there is a number x (1<=x<=5*10^5) in a line.

    Output

      For each case, output the case number first. Then output the minimum number of operations. If he can’t get x, just output -1.

    Sample Input

    3
    2
    6
    13

    Sample Output

    Case 1: 0
    Case 2: 4
    Case 3: 4 



    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    int ans;

    int fff(int a,int b)
    {
        ans++;
        if(a<1||b<2) return 0x3f3f3f3f;
        if(ans>=100) return 0x3f3f3f3f;
        if(a==1&&b==2) return ans;
        b=b-a;
        if(b<a)
            swap(a,b);
        fff(a,b);
    }

    int main()
    {
        int T;
        cin>>T;
        int cas=1;
    while(T--)
    {
        int n;
        cin>>n;
        int cnt=0x3f3f3f3f;
        for(int i=1;i<=n/2;i++)
        {
            ans=0;
            int a=i;int b=n-i;
            if(a>b) swap(a,b);
            cnt=min(cnt,fff(a,b));
        }
        if(cnt>=0x3f3f3f3f&&n!=2) cnt=-1;
        if(n==2) cnt=0;
        printf("Case %d: %d ",cas++,cnt);
    }
        return 0;
    }

  • 相关阅读:
    【折腾】Docker官网下载Docker实在太慢怎么破!!!!!windows 安装docker
    centos7搭建FTP文件服务器--虚拟用户
    AWK简单案例
    SaltStack系统初始化
    ReactNative环境搭配及软件安装
    extundelete工具恢复误删文件
    linux磁盘阵列raid1的搭建教程
    linux中Raid0磁盘阵列的搭建
    子网掩码的计算方法
    linux网络管理命令
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350916.html
Copyright © 2011-2022 走看看