hdoj 3784 继续xxx定律

来源:互联网 发布:tensorflow与spark 编辑:程序博客网 时间:2024/06/05 21:11

xxx定律快要忘了

代码:

#include <stdio.h>#include <string.h>#define M 3000005int 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

0 0
原创粉丝点击