MYF

HDU 5752 Sqrt Bo

题目链接

HDU 5752

题目类型:暴力模拟

题目来源:2016年多校Round3签到题

题目分析

题目大意

给出f(n)=(int)sqrt(n),f2(n)=f(f(n)),问,给定的数字能否在五次操作之内变为1

解析

首先先模拟一下当f(n)=1的情况,n=1,2,3。f2(n)=1的情况,n=4,5,6,7,…,15。这样大概就能发现规律了。当n<(1<<2),满足f(n)=1,当n<(1<<4),满足f(n)=2,当n<(1<<8),满足f(n)=3…所以这样就很好办了,先判断一下这个数字是否是在1<<(32)之内且大于零,然后再一个个去比较即可。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <deque>
#include <algorithm>
#define Memset(a,val) memset(a,val,sizeof(a))
#define PI acos(-1)
#define pb push_back
#define rt(n) (i == n ? '\n' : ' ')
#define hi printf("Hi----------\n")
#define IN freopen("input.txt","r",stdin);
#define OUT freopen("output.txt","w",stdout);
#define debug(x) cout<<"Debug : ---"<<x<<"---"<<endl;
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int maxn=100000+5;
const int mod=1000000007;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
char num[105];
char tmp[30];
int main(){
while (scanf("%s",num)!=EOF) {
if (strlen(num)>10||num[0]=='0') {
puts("TAT");
continue;
}
ll a;
sscanf(num, "%lld",&a);
if (a<(1LL<<2)) {
cout<<1<<endl;
}
else if (a<(1LL<<4)) {
cout<<2<<endl;
}
else if (a<(1LL<<8)) {
cout<<3<<endl;
}
else if (a<(1LL<<16)) {
cout<<4<<endl;
}
else if (a<(1LL<<32)) {
cout<<5<<endl;
}
else{
puts("TAT");
}
}
return 0;
}