xxx定律快要忘了
代码:
#include <stdio.h>
#include <string.h>
#define M 3000005
int a[M];
bool vis[M];
int temp[M];
int main()
{
int n;
while(scanf("%d", &n), n){
int i, j;
for(i = 0; i < n; i ++){
scanf("%d", &a[i]);
}
memset(vis, 0, sizeof(vis));
for(i = 0; i < n; i ++){
if(vis[a[i]]) continue;
int tem = a[i];
while(tem != 1){
if(tem%2 == 0) tem /=2;
else tem = (tem*3+1)/2;
if(tem < 1001)
vis[tem] = 1;
}
}
for(i = n-1, j = 0; i >= 0; i --){
if(vis[a[i]] == 0) temp[j++] = a[i];
}
printf("%d", temp[0]);
for(i = 1; i < j; i ++) printf(" %d", temp[i]);
printf("\n");
}
}
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3784