-
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这样n个有序的数,每次抽出其中奇数位的放到最后,偶数位的放在前面,操作m次,问前x个数分别为什么
解题思路:暴力操作一次,找出每个位置是从上次哪个位置来的,用这个规律就可以找出循环节,也就是操作几次能够变回一开始的样子,m对循环节进行取余,然后对x位暴力地进行剩余次数的模拟
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <functional>
#include <climits>
using namespace std;
#define LL long long
const int INF=0x3f3f3f3f;
int f[1000009];
int n,m,x;
int main()
{
while(~scanf("%d%d%d",&n,&m,&x))
{
int cnt=1;
for(int i=2;i<=n;i+=2) f[cnt++]=i;
for(int i=1;i<=n;i+=2) f[cnt++]=i;
int pos=f[1];
int res=1;
while(pos!=1)
{
res++;
pos=f[pos];
}
m%=res;
int flag=0;
for(int i=1;i<=x;i++)
{
if(flag) printf(" ");
else flag=1;
int k=i;
for(int j=1;j<=m;j++)
k=f[k];
printf("%d",k);
}
printf("\n");
}
return 0;
}