zoukankan      html  css  js  c++  java
  • HDU5752 Sqrt Bo

      题目链接如下:http://acm.hdu.edu.cn/showproblem.php?pid=5752

      题意如下:

      

    Problem Description
    Let's define the function f(n)=n√.

    Bo wanted to know the minimum number y which satisfies fy(n)=1.

    note:f1(n)=f(n),fy(n)=f(fy1(n))

    It is a pity that Bo can only use 1 unit of time to calculate this function each time.

    And Bo is impatient, he cannot stand waiting for longer than 5 units of time.

    So Bo wants to know if he can solve this problem in 5 units of time.
     
    Input
    This problem has multi test cases(no more than 120).

    Each test case contains a non-negative integer n(n<10100).
     
    Output
    For each test case print a integer - the answer y or a string "TAT" - Bo can't solve this problem.
     
     
    分析:由于他说执行开方操作小于等于5次, 因此我们可以得出五次以内开方最终结果为1的范围是[1, 2^32), 然后暴力模拟即可。代码如下:
    /*************************************************************************
        > File Name: HDU5752.cpp
        > Author:
        > Mail:
        > Created Time: 2016年07月28日 星期四 19时40分42秒
     ************************************************************************/
    
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    
    using namespace std;
    typedef long long LL;
    char input[1000];
    int len;
    
    LL trans(char a[])
    {
        LL res = 0;
        for(int i=0; i<len; i++)
        {
            res = res*10 + input[i] - '0';
        }
        return res;
    }
    
    int main()
    {
        while(scanf("%s", input) != EOF)
        {
            len = strlen(input);
            if(len > 10 || (len==1 && input[0]=='0')) printf("TAT
    ");
            else
            {
                LL num = trans(input);
                int res = 0;
                while(num != 1)
                {
                    num = sqrt(num);
                    res++;
                }
                if(res <= 5)
                    printf("%d
    ", res);
                else
                    printf("TAT
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    HttpServlet RequestDispatcher sendredirect和forward
    java中判断字符串是否为数字的方法的几种方法
    apk 解包 打包
    js cookie
    js中的this关键字
    Myeclipse 添加Android开发工具
    List<T> List<?> 区别用法
    mysql 命令
    BZOJ 2281 Luogu P2490 [SDOI2011]黑白棋 (博弈论、DP计数)
    【学习笔记】求矩阵的特征多项式
  • 原文地址:https://www.cnblogs.com/xingxing1024/p/5716088.html
Copyright © 2011-2022 走看看