zoukankan      html  css  js  c++  java
  • Sqrt Bo hdu 5752

    Sqrt Bo

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
    Total Submission(s): 0    Accepted Submission(s): 0


    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.
     
    Sample Input
    233 233333333333333333333333333333333333333333333333333333333
     
    Sample Output
    3 TAT
     
     
     
    题意:给出一个字符串,若开五次根号能开到1,则输出开方次数,否则输出“TAT”。
     
    打了一下午比赛做了一道这么个签到题。。。%>_<%
     
     
     
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    using namespace std;
    #define maxn 1120
    char str[maxn];
    
    int main()
    {
        while(scanf("%s", str)!=EOF)
        {
            int ans = 0;
            long long n = 0;
    
            for(int i=0; str[i] && i<11; i++)
                n = n*10+str[i]-'0';
    
            while(n != 1)
            {
                n = sqrt(n);
                ans ++;
                
                if(ans>6)
                    break;
            }
    
            if(ans <= 5) printf("%d
    ", ans);
    
            else   printf("TAT
    ");
    
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    年薪百万必备能力
    二叉搜索树
    字符串和字符串模式匹配
    2006最后寄语
    “豆瓣”式推荐
    什么是LOMO?
    大国崛起
    马季之死
    时间的价值(The Value Of Time)
    我读雅虎的“花生酱宣言”
  • 原文地址:https://www.cnblogs.com/daydayupacm/p/5708195.html
Copyright © 2011-2022 走看看