// B1005 继续(3n+1)猜想 (25分).cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
/*
题意:所有中间过程的数字称为非关键字,也就是找出所有非中间过程的字;
解题:
1、对输入的每一个数进行3n猜想,每个过程都录入hash,置为false
2、记得统计数字,方便空格取消
3、排序,
4、遍历的过程判断是否为true,是则输出,
learn && wrong
1、hash数字不能开太小了,1000以上,也可以在计算过程中判断一个数是否大于100,大于100就不管他,因为给出的数字在100以内
2、sort是算法库里的东西
3、还要累计多少个是非关键字,才能最后不输出空格!
*/
include <iostream>
include <cstring>
include <algorithm>
using namespace std;
int str[100];
bool hash1[1010];
int main()
{
memset(hash1, true, sizeof(hash1));
int n, m;
cin >> n;
for (int i = 0;i < n;++i) { //输入一个处理一个
cin >> str[i];
m = str[i];
while (m != 1) {
if (m % 2 == 0) m = m / 2;
else m = 3 * m + 1;
hash1[m] = false;
}
}
int num = 0;
for (int i = 0;i < n;++i) {
if (hash1[str[i]] == true) ++num;
}
sort(str, str + n); //升序排列
for (int i = n - 1;i >= 0;--i) {
if (hash1[str[i]] == true) {
cout << str[i];
num--;
if (num != 0) cout << " ";
}
}
return 0;
}
网友评论