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"); } }
hdoj 3784 继续xxx定律,布布扣,bubuko.com
原文:http://blog.csdn.net/shengweisong/article/details/38711621