HDU5752-Sqrt Bo

Sqrt Bo

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

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(fy?1(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

题意就是一个数最多开5次根号,能否变成1,输出开根号的次数,如果不存在或者超过5次就输出TAT

2*2=4,4*4=16,16*16=256,256*256=65536;65536*65536=4294967296,所以4294967296为极值了,直接与这个数比较就可以,

当然也可以和4013729316这个数比较,这个数连开5次根号,为1.999577。。。

因为数比较大,所以用数组存大数。

先判断一下,如果数的位数大于10位,肯定TAT,再将数组里的数变成我们要求的大数,再判断是否<极值数,然后再开根号,记录次数就可以了。

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10;
typedef long long ll;
char a[N];
int main(){
    int len,ans;
    ll num,cnt;
    while(~scanf("%s",&a)){
        len=strlen(a);
        if(len>10)
            printf("TAT\n");
        else{
            num=0;
            for(int i=0;i<len;i++){                       //将数组里的数变成要求的数
                num=num*10+a[i]-‘0‘;
            }
            if(num>=4013729316||num==0)
                printf("TAT\n");
            else{
                ans=0;
                while(num!=1){
                   num=(ll)sqrt(num*1.0);                 //因为向下取整,所以强制转换一下
                   ans++;
                }
                printf("%d\n",ans);
            }
        }
    }
    return 0;
}

==

时间: 2024-11-16 14:35:42

HDU5752-Sqrt Bo的相关文章

HDU5752 Sqrt Bo(2016多校训练)

Sqrt Bo Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1173    Accepted Submission(s): 528 Problem Description Let's define the function f(n)=⌊n−−√⌋ . Bo wanted to know the minimum number y w

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 wh

hdu 5752 Sqrt Bo

Sqrt Bo Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 980    Accepted Submission(s): 452 Problem Description Let's define the function f(n)=⌊n√⌋. Bo wanted to know the minimum number y which

【模拟】HDU 5752 Sqrt Bo

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5752 题目大意: 定义f(n)=⌊√n⌋,fy(n)=f(fy-1(n)),求y使得fy(n)=1.如果y>5输出TAT.(n<10100) 题目思路: [模拟] 5层迭代是232,所以特判一下层数是5的,其余开根号做.注意数据有0. 队友写的. 1 #include<stdio.h> 2 #include<string.h> 3 #include<math.h&g

HDU 5752 Sqrt Bo (思维题) 2016杭电多校联合第三场

题目:传送门. 题意:一个很大的数n,最多开5次根号,问开几次根号可以得到1,如果5次还不能得到1就输出TAT. 题解:打表题,x1=1,x2=(x1+1)*(x1+1)-1,以此类推.x5是不超过long long的,判断输出即可. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; typedef long long

HDU 5754 Life Winner Bo 组合博弈

Life Winner Bo Problem Description Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G. The size of the chessboard is N×M.The top left corner is numbered(1,1) and the lower right corner is numberd (N,M). For each game,B

5754Life Winner Bo

给定一个n*m的矩阵,有四种棋子(国际象棋的王,王后,骑士,车).起点在(1,1)先走到(n,m)获胜. 分析:车是nim博弈.王后是威佐夫博弈.王和骑士写两个1000*1000的预处理即可. hdu5754Life Winner Bo 题目连接 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 co

HDU-5754 Life Winner Bo (博弈论)

好久没有整题目了,并不是没有好的题目整,只是自己懒了太懒了太懒了...赶紧整理几个题补一下自己的罪过... Description Bo is a "Life Winner".He likes playing chessboard games with his girlfriend G.The size of the chessboard is N×M .The top left corner is numbered(1,1) and the lower right corner is

[leedcode 69] Sqrt(x)

Implement int sqrt(int x). Compute and return the square root of x. public class Solution { //本题利用了牛顿迭代法:设r是f(x) = 0的根(x^2-k=f(x)),选取x0作为r初始近似值,过点(x0,f(x0))做曲线y = f(x)的切线L,L的方程为y = f(x0 //)+f'(x0)(x-x0),求出L与x轴交点的横坐标 x1 = x0-f(x0)/f'(x0),称x1为r的一次近似值.