http://acm.hdu.edu.cn/showproblem.php?pid=2991
....暴力模拟
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
const double pi=acos(-1.0);
double eps=0.000001;
int get(int x)
{
x=x*x;
x=x/100;
int tmp=0;
for (int i=1;i<=4;i++)
{
tmp=tmp*10+x%10;
x/=10;
}
x=0;
for (int i=1;i<=4;i++)
{
x=x*10+tmp%10;
tmp/=10;
}
return x;
}
int main()
{
int n;
int cun=1;
while( scanf("%d",&n)!=EOF)
{
if (!n)break;
set<int>sb;
while(1)
{
if (sb.find(n)==sb.end())
sb.insert(n);
else break;
n=get(n);
// printf("%d\n",n);
}
printf("%d\n",sb.size());
}
return 0;
}
本文介绍了一道来自HDU OJ的2991号题目,通过使用C++实现一种暴力模拟算法来解决该问题。主要思路是对于输入的整数进行特定的操作,包括平方、移位和重组数字等步骤,直到出现重复的数字序列为止,并输出整个过程中遇到的不同数字的数量。
256

被折叠的 条评论
为什么被折叠?



