1042. Shuffling Machine (20)

简介: Shuffling is a procedure used to randomize a deck of playing cards.

Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid "inside jobs" where employees collaborate with gamblers by performing inadequate shuffles, many casinos employ automatic shuffling machines. Your task is to simulate a shuffling machine.

The machine shuffles a deck of 54 cards according to a given random order and repeats for a given number of times. It is assumed that the initial status of a card deck is in the following order:

S1, S2, ..., S13, H1, H2, ..., H13, C1, C2, ..., C13, D1, D2, ..., D13, J1, J2

where "S" stands for "Spade", "H" for "Heart", "C" for "Club", "D" for "Diamond", and "J" for "Joker". A given order is a permutation of distinct integers in [1, 54]. If the number at the i-th position is j, it means to move the card from position i to position j. For example, suppose we only have 5 cards: S3, H5, C1, D13 and J2. Given a shuffling order {4, 2, 5, 3, 1}, the result will be: J2, H5, D13, S3, C1. If we are to repeat the shuffling again, the result will be: C1, H5, S3, J2, D13.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer K (<= 20) which is the number of repeat times. Then the next line contains the given order. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print the shuffling results in one line. All the cards are separated by a space, and there must be no extra space at the end of the line.


input:

2

36 52 37 38 3 39 40 53 54 41 11 12 13 42 43 44 2 4 23 24 25 26 27 6 7 8 48 49 50 51 9 10 14 15 16 5 17 18 19 1 20 21 22 28 29 30 31 32 33 34 35 45 46 47


output:

S7 C11 C10 C12 S1 H7 H8 H9 D8 D9 S11 S12 S13 D10 D11 D12 S3 S4 S6 S10 H1 H2 C13 D2 D3 D4 H6 H3 D13 J1 J2 C1 C2 C3 C4 D1 S5 H5 H11 H12 C6 C7 C8 C9 S2 S8 S9 H10 D5 D6 D7 H4 H13 C5

#include <iostream>
using namespace std;
int N = 54;

int main(int argc, const char * argv[]) {
    string s0[54] =
    {   "S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10", "S11", "S12", "S13",
        "H1", "H2", "H3", "H4", "H5", "H6", "H7", "H8", "H9", "H10", "H11", "H12", "H13",
        "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", "C11", "C12", "C13",
        "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "D10", "D11", "D12", "D13",
        "J1", "J2"
    };
    string s[N];
//    string s0[5] = {"S3", "H5", "C1", "D13" , "J2"};
    
    int m, n[N];
    cin >> m;
    for(int i = 0; i < N; i++){
        cin >> n[i];
    }
    
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < N; j++) {
            s[n[j]-1] = s0[j];
        }
        for (int i = 0; i < N; i++) {
            s0[i] = s[i];
        }
    }
    
    for (int i = 0; i < N; i++) {
        if (i != 0) cout << ' ';
        cout << s[i];
    }
    cout << endl;
    return 0;
}

/*
2
36 52 37 38 3 39 40 53 54 41 11 12 13 42 43 44 2 4 23 24 25 26 27 6 7 8 48 49 50 51 9 10 14 15 16 5 17 18 19 1 20 21 22 28 29 30 31 32 33 34 35 45 46 47
 S7 C11 C10 C12 S1 H7 H8 H9 D8 D9 S11 S12 S13 D10 D11 D12 S3 S4 S6 S10 H1 H2 C13 D2 D3 D4 H6 H3 D13 J1 J2 C1 C2 C3 C4 D1 S5 H5 H11 H12 C6 C7 C8 C9 S2 S8 S9 H10 D5 D6 D7 H4 H13 C5
 
2
4 2 5 3 1
 */



目录
相关文章
|
4月前
|
数据采集 监控 测试技术
JKI State Machine的特点与详细介绍
JKI State Machine的特点与详细介绍
78 0
JKI State Machine的特点与详细介绍
|
传感器 监控 自动驾驶
Machine Learning
Machine Learning
94 0
|
机器学习/深度学习 算法 Python
Machine Learning-L7-最大熵模型
Machine Learning-L7-最大熵模型
Machine Learning-L7-最大熵模型
|
机器学习/深度学习
这就是Machine Learning
这就是Machine Learning
137 0
这就是Machine Learning
|
Java 虚拟化 C++
Stack based vs Register based Virtual Machine Architecture
进程虚拟机简介 一个虚拟机是对原生操作系统的一个高层次的抽象,目的是为了模拟物理机器,本文所谈论的是基于进程的虚拟机,而不是基于系统的虚拟机,基于系统的虚拟机可以用来在同一个平台下去运行多个不同的硬件架构的操作系统,常见的有kvm,xen,vmware等,而基于进程的虚拟机常见的有JVM,PVM(python虚拟机)等,java和python的解释器将java和python的代码编译成JVM和P
3681 0
|
数据挖掘
Machine learning preface
Machine learning Preface Definition T: Task E: Experience P: Performance Sequence: T -> E -> P Supervised learning Definition Give the right answer...
923 0
|
搜索推荐 Python 算法
Factorization Machine
Factorization Machine---因子分解机 ①target function的推导 logistics regression algorithm model中使用的是特征的线性组合,最终得到的分割平面属于线性模型,但是线性模型就只能处理线性问题,所以对于非线性的问题就有点难处理了,对于这些复杂问题一般是两种解决方法①对数据本身进行处理,比如进行特征转换,和函数高维扩展等等。
1109 0
Virtual Machine
虚拟机 关于内存 CPU通过总线来管理内存, 总线分为3种 控制总线: 指定对内存进行的是读还是写操作 地址总线: 用来表示内存中的地址, 一根地址电线对应一个0|1bit, 如果有4根线, 则CPU对内存的操作就是00, 01, 10, 11这四个地址, 如果有32根, 则CPU对内存的操作就是...
1004 0