wustoj 1093 NEW RDSP MODE I

1093: NEW RDSP MODE I

Time Limit: 1 Sec   Memory Limit: 128 MB
[ Submit][ Status][ Web Board]

Problem Description

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.

Input

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.

Output

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.

Sample Input

5 1 2
5 2 2

Sample Output

2 4
4 3

HINT


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.



Source

思路:

n、m都挺大,模拟或者对n个元素直接操作肯定会TLE。

这题的突破口在于:x的范围很小

那么预处理每个位置的上一个位置,对前x个点处理就够了,从后往前推,每次找到它的前一个位置,当然位置也是周期性出现的,而且循环节不超过n,这样复杂度就降到O(x*n)了,可以过了。


ps:每个位置的前一个位置其实可以推公式的,我是算出来的,时间要的多一点。


代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
//#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 1000005
#define MAXN 100005
#define mod 1000000007
#define INF 0x3f3f3f3f
using namespace std;

int n,m,x,k,ans,cnt;
int pre[maxn],tt[maxn],pos[maxn];

void presolve()
{
    int i,j,t,cur,now,st,step;
    memset(pre,-1,sizeof(pre));
    cnt=0;
    k=n>>1;
    for(i=0;i<n;i++)
    {
        if(pre[i]!=-1) continue ;
        st=now=i;
        step=0;
        cnt++;
        while(1)
        {
            pos[st]=cnt;
            cur=st;
            step++;
            if(st&1) st=st>>1;
            else st=(st>>1)+k;
            pre[st]=cur;
            if(st==now) break ;
        }
        tt[cnt]=step;
    }
}
void solve()
{
    int i,j,s,st;
    for(i=0;i<x;i++)
    {
        s=m%tt[pos[i]];
        st=i;
        for(j=0;j<s;j++)
        {
            st=pre[st];
        }
        if(i==0) printf("%d",st+1);
        else printf(" %d",st+1);
    }
    printf("\n");
}
int main()
{
    int i,j;
    while(~scanf("%d%d%d",&n,&m,&x))
    {
        presolve();
        solve();
    }
    return 0;
}










1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REAdMe.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REAdMe.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看READme.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值