• HDU 5752 Sqrt Bo【枚举,大水题】


    Sqrt Bo

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


    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
     
    Author
    绍兴一中
     
    Source
    题意:给你一个数,对这个数进行连续开方,这个数能在5次以内开方(每次开方都是向下取整),使得最后结果等于1,输出开方次数,否则输出TAT
    分析:看起来这道题怪吓人的,10^100次,lfh跟我说这道题很难,要用字符串啥玩意来着,然后算什么2^32的数还是啥的,弱弱菜鸡就随手扔了一个代码
    枚举一波连续开5次根的数,然后。。。。竟然AC了,旁边的lfh懵逼了:这也行?(弱弱的说他好像Wa了好几发的样子),此题数据是10^100,建议开long double型
    其次是。。。。。我特别嫌弃这种要连续输入的题,每次害得我找错误找半天QAQ!
    下面给出AC代码:
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long double ll;
     4 inline ll gcd(ll x)
     5 {
     6     int k,t;
     7     int flag=0;
     8     for(k=1;k<=5;k++)
     9     {
    10         x=(long long)sqrt(x);
    11         if(x==1)
    12         {
    13             flag=1;
    14             t=k;
    15             break;
    16         }
    17     }
    18     if(flag)
    19         return t;
    20     return 0;
    21 }
    22 int main()
    23 {
    24     ll n;
    25     while(cin>>n)
    26     {
    27     if(!gcd(n))
    28         cout<<"TAT"<<endl;
    29     else cout<<gcd(n)<<endl;
    30     }
    31     return 0;
    32 }
     
  • 相关阅读:
    java常见面试题汇总(三)
    Java学习流程图(学习路线、书籍、教程推荐)
    java开发面试题:spring面试题总结
    2014.11.12模拟赛【最大公因数】
    2014.11.12模拟赛【最小公倍数】| vijos1047最小公倍数
    vijos1781 同余方程
    vijos1777 引水入城
    2014.10.31我出的模拟赛【天神下凡】
    voijs1883 月光的魔法
    2014.10.31我出的模拟赛【藏宝图】
  • 原文地址:https://www.cnblogs.com/ECJTUACM-873284962/p/7148847.html
Copyright © 2020-2023  润新知