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
  • 操作
  •        
  • 题意是有从1--n的数,从里面挑选出所有的偶数位置,放在这些数的前面(偶数位置在前,奇数位置在后),求经过m次这样的变换,前 x个数是什么。
  • 对于偶数位置,每次变换后的位置x'=x/2;
  • 对于奇数位置,每次变换后的位置x'=x/2+n/2;
  • 转换一下,偶数x=2*x',奇数x=2*x'-n;
  • 可以看出,无论时奇数还是偶数位置,都是x=x' *2对n取余,
  • 经过m次变换,就是2的m次幂,还要注意,当N为偶数的时候要+1,因为N为偶数的时候,取模后下标可能为0,当N为奇数时,第N位数在变换中位置是不变的,所以不必考虑
  • 倒推,从末状态位置1推出初状态的位置,然后推出其他位置
  • #include <iostream>
    #include <iomanip>
    #include<stdio.h>
    #include<string.h>
    #include<stack>
    #include<stdlib.h>
    #include<queue>
    #include<map>
    #include<math.h>
    #include<algorithm>
    #include<vector>
    #define mem(a,b) memset(a,b,sizeof(a))
    #define N 105
    #define inf 1000000007
    #define ll long long
    using namespace std;
    ll fast(ll x,ll n,ll mod)
    {
        ll res=1;
        while(n)
        {
            if(n&1)
            res=(res*x)%mod;
            x=((x%mod)*(x%mod))%mod;
            n>>=1;
        }
        return res;
    }
    int main()
    {
        ll n,m,x,tmp,ans;
        while(cin>>n>>m>>x)
        {
            if(n%2==0)n++;
            tmp=fast(2,m,n);
            ans=tmp;
            cout<<tmp;
            for(int i=2;i<=x;i++)
            {
                ans+=tmp;
                ans%=n;
                cout<<" "<<ans;
            }
            cout<<endl;
        }
    }



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值