-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathB1005.cpp
45 lines (43 loc) · 986 Bytes
/
B1005.cpp
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
/*
* hint:
* 测试点3,4:存在计算数字过程中超过 100 的数字,如果定义的 hash_table 容量较小,需要避免溢出
*/
#include <iostream>
#include <algorithm>
#define MAX_N 105
#define MAX_K 105
using namespace std;
bool isCovered[MAX_N] = {};
int arr[MAX_K] = {};
int main()
{
int k, n;
scanf("%d", &k);
for (int i = 0; i < k; i++)
{
scanf("%d", &arr[i]);
n = arr[i];
while (n != 1)
{
if (n % 2 == 0)
n /= 2;
else
n = (3 * n + 1) / 2;
if (n < MAX_N)
isCovered[n] = true;
}
}
sort(arr, arr + k);
bool isFirstOutput = true;
for (int i = k - 1; i >= 0; i--)
if (! isCovered[arr[i]])
{
if (isFirstOutput)
{
printf("%d", arr[i]);
isFirstOutput = false;
}
else printf(" %d", arr[i]);
}
return 0;
}