NBUT 1225 NEW RDSP MODE I

  • [1225] NEW RDSP MODE I

  • 时间限制: 1000 ms 内存限制: 131072 K
  • 问题描述

  • Little A has became fascinated with the game Dota recently, but he is not a good player. In all the modes, the rdsp Mode is popular on online, in this mode, little A always loses games if he gets strange heroes, because, the heroes are distributed randomly.

    Little A wants to win the game, so he cracks the code of the rdsp mode with his talent on programming. The following description is about the rdsp mode:

    There are N heroes in the game, and they all have a unique number between 1 and N. At the beginning of game, all heroes will be sorted by the number in ascending order. So, all heroes form a sequence One.

    These heroes will be operated by the following stages M times:

    1.Get out the heroes in odd position of sequence One to form a new sequence Two;

    2.Let the remaining heroes in even position to form a new sequence Three;

    3.Add the sequence Two to the back of sequence Three to form a new sequence One.

    After M times' operation, the X heroes in the front of new sequence One will be chosen to be Little A's heroes. The problem for you is to tell little A the numbers of his heroes.

  • 输入
  • There are several test cases.
    Each case contains three integers N (1<=N<1,000,000), M (1<=M<100,000,000), X(1<=X<=20).
    Proceed to the end of file.
  • 输出
  • For each test case, output X integers indicate the number of heroes. There is a space between two numbers. The output of one test case occupied exactly one line.
  • 样例输入
  • 5 1 2
    5 2 2
  • 样例输出
  • 2 4
    4 3
  • 提示
  • In case two: N=5,M=2,X=2,the initial sequence One is 1,2,3,4,5.After the first operation, the sequence One
    is 2,4,1,3,5. After the second operation, the sequence One is 4,3,2,1,5.So,output 4 3.
  • 来源
  • 辽宁省赛2010

    题目意思是:输入n,m,x,刚开始有一个1……n的排列,然后定义了一种操作,是将数组中的奇数位的数字选出来,按照顺序放到数组最后面,偶数位按照顺序放到奇数位的后面,进行m次这样的操作之后, 输出 前x个数字。
    分析:找到循环节T,利用T去约m,然后再将很小的m拿去模拟,输出前x个.

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cmath>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    using namespace std;
    
    typedef long long LL;
    const int mx = 1e6 + 10;
    const int inf = 0x3f3f3f3f;
    
    int num[mx];
    int n,m,x;
    int find_t() {          //找循环周期T
        int cnt=0,cur=1;
        do{
            if(cur*2<=n)
                cur*=2;
            else
                cur=(cur-n/2)*2-1;
            cnt++;
        } while(cur!=1);
        return cnt;
    }
    int main() {
        while(~scanf("%d%d%d",&n,&m,&x)) {
            for(int i=1; i<=n; i++)
                num[i]=i;
            int T=find_t();
            m%=T;
            for(int i=1; i<=x; i++) {
                if(i!=1)
                    printf(" ");
                for(int j=1; j<=m; j++) {
                    if(num[i]*2<=n)
                        num[i]*=2;
                    else
                        num[i]=(num[i]-n/2)*2-1;
                }
                printf("%d",num[i]);
            }
            printf("\n");
        }
        return 0;
    }
    


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值