hdoj 5752

Let‘s define the function f(n)=?n??√?f(n)=?n?.

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

note:f1(n)=f(n),fy(n)=f(fy?1(n))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.

InputThis problem has multi test cases(no more than 120120).

Each test case contains a non-negative integer n(n<10100)n(n<10100).OutputFor each test case print a integer - the answer yyor a string "TAT" - Bo can‘t solve this problem.Sample Input

233
233333333333333333333333333333333333333333333333333333333

Sample Output

3
TAT
 1 /*
 2 要在五次内开跟达到1,第一次要在4以内,第二次在16以内,
 3     第三次256,第四次65536,第五次4294967296,所以超过10位的都是TAT*/
 4
 5 #include<cstdio>
 6 #include<iostream>
 7 #include<cstring>
 8 #include<queue>
 9 #include<cmath>
10 using namespace std;
11
12 char ch[110];
13
14 long long i;
15 const long long num=4294967296-1;
16
17 int main()
18 {
19     while(~scanf("%s",ch))
20     {
21         int r=strlen(ch);
22         int l=0;
23         while(ch[l]==‘0‘) l++;
24         if(r-l>10)
25         {
26             printf("TAT\n");
27             continue ;
28         }
29         i=0;
30         while(l<r)
31         {
32             i=i*10+(ch[l]-‘0‘);
33             l++;
34         }
35         //cout<<i<<endl;
36         if(i>num||i==0)
37         {
38             printf("TAT\n");
39         }
40         else
41         {
42             int ii=0;
43             while(i!=1)
44             {
45                 i=(long long )sqrt(i);
46                 //cout<<i<<endl;
47                 ii++;
48             }
49             printf("%d\n",ii);
50         }
51     }
52 }
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <math.h>
 4 #include <string.h>
 5 using namespace std;
 6 #define MAXN 10000000
 7 char str [MAXN];
 8 int main()
 9 {
10     while(~scanf("%s",str)){
11         int len=strlen(str);
12         if(len>10){printf("TAT");continue;}
13         else{
14             long long  n=0;bool flag=0;
15             for(int i=0;i<len;i++) n=n*10+str[i]-‘0‘;
16             for(int i=1;i<=5;i++){
17                 n=sqrt(n);
18                 if(n==1){flag=1;printf("%d\n",i);break;}
19             }
20             if(flag==0) printf("TAT");
21         }
22     }
23     return 0;
24 }
时间: 2024-10-24 13:59:17

hdoj 5752的相关文章

【HDOJ】4328 Cut the cake

将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. 1 /* 4328 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector>

POJ Xiangqi 4001 &amp;&amp; HDOJ 4121 Xiangqi

题目链接(POJ):http://poj.org/problem?id=4001 题目链接(HDOJ):http://acm.hdu.edu.cn/showproblem.php?pid=4121 Xiangqi Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1108   Accepted: 299 Description Xiangqi is one of the most popular two-player boa

【HDOJ】4956 Poor Hanamichi

基本数学题一道,看错位数,当成大数减做了,而且还把方向看反了.所求为最接近l的值. 1 #include <cstdio> 2 3 int f(__int64 x) { 4 int i, sum; 5 6 i = sum = 0; 7 while (x) { 8 if (i & 1) 9 sum -= x%10; 10 else 11 sum += x%10; 12 ++i; 13 x/=10; 14 } 15 return sum; 16 } 17 18 int main() { 1

HDOJ 4901 The Romantic Hero

DP....扫两遍组合起来 The Romantic Hero Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 547    Accepted Submission(s): 217 Problem Description There is an old country and the king fell in love with a

【HDOJ】1099 Lottery

题意超难懂,实则一道概率论的题目.求P(n).P(n) = n*(1+1/2+1/3+1/4+...+1/n).结果如果可以除尽则表示为整数,否则表示为假分数. 1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXN 25 5 6 __int64 buf[MAXN]; 7 8 __int64 gcd(__int64 a, __int64 b) { 9 if (b == 0) return a; 10 else return

【HDOJ】2844 Coins

完全背包. 1 #include <stdio.h> 2 #include <string.h> 3 4 int a[105], c[105]; 5 int n, m; 6 int dp[100005]; 7 8 int mymax(int a, int b) { 9 return a>b ? a:b; 10 } 11 12 void CompletePack(int c) { 13 int i; 14 15 for (i=c; i<=m; ++i) 16 dp[i]

HDOJ 3790 双权值Dijkstra

1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <cstring> 5 using namespace std; 6 7 const int INF = 1000000; 8 const int MAXSIZE = 1005; 9 10 int map[MAXSIZE][MAXSIZE]; 11 int price[MAXSIZE][MAXSIZE]; 1

HDOJ 1217 Floyed Template

1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <cstring> 5 #include<map> 6 using namespace std; 7 8 map<string,int>name; 9 const int INF = 1000000; 10 const int MAXSIZE = 1005; 11 const int

【模拟】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