• 每日一九度之 题目1033:继续xxx定律


    时间限制:1 秒

    内存限制:32 兆

    特殊判题:

    提交:5502

    解决:1351

    题目描述:
        当n为3时,我们在验证xxx定律的过程中会得到一个序列,3,5,8,4,2,1,将3称为关键数,5,8,4,2称为覆盖数。现在输入n个数字 a[i],根据关键数与覆盖数的理论,我们只需要验证其中部分数就可以确定所有数满足xxx定律,输出输入的n个数中的关键数。如果其中有多个关键数的话 按照其输入顺序的逆序输出。
    输入:
        输入数据包含多个用例,每个用例首先包含一个整数n,然后接下来一行有n个整数a[i],其中: 1<=n<=500, 1<a[i]<=1000
    输出:
        请计算并输出数组a中包含的关键数,并按照其输入顺序的逆序输出,每个用例输出占一行。
    样例输入:
    3
    3 8 4
    5
    3 8 4 7 15
    5
    3 8 4 15 7
    0
    样例输出:
    3
    15 7 3
    7 15 3

    把输入的数每个都用xxx定律算一下,不会重复出现的就是关键数。重复出现过的就是覆盖数。

    //Asimple
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <cctype>
    #include <cstdlib>
    #include <stack>
    #include <cmath>
    #include <map>
    #include <string>
    #include <queue>
    #define INF 100000
    using namespace std;
    const int maxn = 1005;
    typedef long long ll;
    int n, num;
    int a[maxn], b[505];
    
    int main(){
        while( scanf("%d",&n) && n ){
            memset(a,0,sizeof(a));
            for(int i=0; i<n; i++){
                scanf("%d",&b[i]);
            }
            for(int i=0; i<n; i++){
                int t = b[i];
                while( t != 1 ){
                    if( t & 1 ){
                        t = ( 3 * t + 1 ) / 2;
                    } else {
                        t /= 2 ;
                    }
                    if( t < 1001 ) a[t] = 1;
                }
            }
            bool f = false;
            for(int i=n-1; i>=0; i--){
                if( a[b[i]] == 0 ){
                    if( f ){
                        printf(" ");
                    }
                    printf("%d",b[i]);
                    f = true;
                }
            }
            printf("
    ");
        }
        return 0;
    }
    低调做人,高调做事。
  • 相关阅读:
    jQuery
    写日志文件
    游标
    jdk与jre的区别
    八段锦练习口诀及作用
    语音网关FXO与FXS的工作原理 FXO与FXS区别
    office 2007安装后右键单击新建没有快捷方式问题解决方法
    什么是STUN?
    【引】[翻译]Irrlicht引擎里的冲突检测与响应
    [原创]IrrLicht中MS3D模型骨骼动画支持bug的排除
  • 原文地址:https://www.cnblogs.com/Asimple/p/5868794.html
Copyright © 2020-2023  润新知