题意,给你52张,将L-R的牌放到开头,重复T次,问最后的结果是什么
Problem Description
Bearchild is playing a card game with himself. But first of all, he needs to shuffle the cards. His strategy is very simple: After putting all the cards into a single stack,
he takes out some cards in the middle, from the L-th to the R-th when counting from top to bottom, inclusive, and puts them on the top. He repeats this action again
and again for N times, and then he regards his cards as shuffled.
Given L,R and N, and the initial card stack, can you tell us what will the card stack be like after getting shuffled?
Input
First line contains an integer T(1 <= T <= 1000), which is the test cases.
For each test case, first line contains 52 numbers(all numbers are distinct and between 1 and 52), which is the card number of the stack, from top to bottom.
Then comes three numbers, they are N, L and R as described. (0<=N<=10
9, 1<=L<=R<=52)
Output
For each test case, output "Case #X:", X is the test number, followed by 52 numbers, which is the card number from the top to bottom.Note that you should output one and only
one blank before every number.
Sample Input
1
13 2 10 50 1 28 37 32 30 46 19 47 33 41 24 52 27 42 49 18 9 48 23 35 31 8 7 12 6 5 3 22 43 36 51 40 26 4 44
17 39 38 15 14 25 16 29 20 21 45 11 34
902908328 38 50
Sample Output
Case #1: 26 4 44 17 39 38 15 14 25 16 29 20 21 45 13 2 10 50 1 28 37 32 30 46 19 47 33 41 24 52 27 42 49 18
9 48 23 35 31 8 7 12 6 5 3 22 43 36 51 40 11 34
Author
elfness@UESTC_Oblivion
Source
2012 Multi-University Training Contest 6
题解:找循环节...
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[1111][55],b[55];
int main()
{
int T,i,j,k,m,n;
int l,r;
scanf("%d",&T);
for(int _=1;_<=T;_++) {
for(i=1;i<=52;i++) {
scanf("%d",&b[i]);
a[0][i]=i;
}
scanf("%d%d%d",&n,&l,&r);
for(i=1;;i++) {
k=1;
for(j=l;j<=r;j++) a[i][k++]=a[i-1][j];
for(j=1;j<l;j++) a[i][k++]=a[i-1][j];
for(j=1;j<=r;j++) {
if(a[i][j]!=j) break;
}
if(j>r) break;
}
m=i;
n=n%m;
printf("Case #%d:",_);
for(i=1;i<=r;i++) {
printf(" %d",b[a[n][i]]);
}
for(i=r+1;i<=52;i++) {
printf(" %d",b[i]);
}
printf("\n");
}
return 0;
}