【模拟】HDU 5752 Sqrt Bo

本文解析了HDU 5752题目的解题思路,通过模拟算法解决数学函数迭代问题,当函数f(n)=⌊√n⌋,fy(n)=f(fy-1(n)),求y使得fy(n)=1,特别处理y>5的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:

  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>
 4 int main()
 5 {
 6     char st[150];
 7     int temp;
 8     int ans;
 9     while(scanf("%s",st)!=EOF)
10     {
11         if (st[0]=='0' || strlen(st)>10 || strlen(st)==10 && strcmp(st,"4294967295")>0)
12             printf("TAT\n");
13         else
14         if (strlen(st)==10 && strcmp(st,"2147483647")>0)
15             printf("5\n");
16         else
17         {
18             ans=0;
19             sscanf(st,"%d",&temp);
20             while(temp!=1)
21             {
22                 temp=(int)(sqrt(double(temp)));
23                 ans++;
24             }
25             if (ans==0) ans=1;
26             printf("%d\n",ans);
27         }
28     }
29     return 0;
30 }
View Code

 

转载于:https://www.cnblogs.com/Coolxxx/p/5769030.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值