2.8.5 完美洗牌术 Stack 'em Up

来源:互联网 发布:朝鲜导弹技术 知乎 编辑:程序博客网 时间:2024/05/18 01:11

PC/UVA 110205/10205

水题。模拟

//author: CHC//First Edit Time:2014-01-22 13:06//Last Edit Time:2014-01-22 13:22//Filename:1.cpp#include <iostream>#include <cstdio>#include <string.h>#include <queue>#include <algorithm>using namespace std;int type[120][60],n;char value[13][10]={    "2","3","4","5","6","7","8","9","10","Jack","Queen","King","Ace"};char suit[4][10]={    "Clubs","Diamonds","Hearts","Spades"};struct p{    int val_num;    char val[10];    char suit[10];}cs[53];char t[1000];void init(){    int num=0;    for(int i=0;i<4;i++){        for(int j=0;j<13;j++){            cs[++num].val_num=j;            strcpy(cs[num].val,value[j]);            strcpy(cs[num].suit,suit[i]);        }    }}void tran(int wh){    p cs1[53]={ 0 };    for(int i=1;i<=52;i++){        int posi=type[wh][i],posj=i;        cs1[posj]=cs[posi];    }    for(int i=1;i<=52;i++)cs[i]=cs1[i];}int main(){    int tt,flag=0;    scanf("%d",&tt);    while(tt--){        if(flag)puts("");        flag=1;        scanf("%d",&n);        for(int i=1;i<=n;i++)        for(int j=1;j<=52;j++)            scanf("%d",&type[i][j]);        getchar();        init();        while(gets(t)!=NULL&&strcmp(t,"")!=0){            int x;            sscanf(t,"%d",&x);            tran(x);        }        for(int i=1;i<=52;i++)printf("%s of %s\n",cs[i].val,cs[i].suit);    }    return 0;}



Stack 'em Up

 

The Big City has many casinos. In one of them, the dealer cheats. She has perfected several shuffles; each shuffle rearranges the cards in exactly the same way whenever it is used. A simple example is the ``bottom card" shuffle, which removes the bottom card and places it at the top. By using various combinations of these known shuffles, the crooked dealer can arrange to stack the cards in just about any particular order.

You have been retained by the security manager to track this dealer. You are given a list of all the shuffles performed by the dealer, along with visual cues that allow you to determine which shuffle she uses at any particular time. Your job is to predict the order of the cards after a sequence of shuffles.

A standard playing card deck contains 52 cards, with 13 values in each of four suits. The values are named 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace. The suits are named Clubs, Diamonds, Hearts, Spades. A particular card in the deck can be uniquely identified by its value and suit, typically denoted value > of suit >. For example, ``9 of Hearts" or ``King of Spades." Traditionally a new deck is ordered first alphabetically by suit, then by value in the order given above.

Input

The input begins with a single positive integer on a line by itself indicating the number of test cases, followed by a blank line. There is also a blank line between two consecutive inputs.

Each case consists of an integer n$ \le$100, the number of shuffles that the dealer knows. Then follow n sets of 52 integers, each comprising all the integers from 1 to 52 in some order. Within each set of 52 integers, i in position j means that the shuffle moves the ith card in the deck to position j.

Several lines follow, each containing an integer k between 1 and n. These indicate that you have observed the dealer applying the kth shuffle given in the input.

Output

For each test case, assume the dealer starts with a new deck ordered as described above. After all the shuffles had been performed, give the names of the cards in the deck, in the new order. The output of two consecutive cases will be separated by a blank line.

Sample Input

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

Sample Output

King of Spades2 of Clubs4 of Clubs5 of Clubs6 of Clubs7 of Clubs8 of Clubs9 of Clubs10 of ClubsJack of ClubsQueen of ClubsKing of ClubsAce of Clubs2 of Diamonds3 of Diamonds4 of Diamonds5 of Diamonds6 of Diamonds7 of Diamonds8 of Diamonds9 of Diamonds10 of DiamondsJack of DiamondsQueen of DiamondsKing of DiamondsAce of Diamonds2 of Hearts3 of Hearts4 of Hearts5 of Hearts6 of Hearts7 of Hearts8 of Hearts9 of Hearts10 of HeartsJack of HeartsQueen of HeartsKing of HeartsAce of Hearts2 of Spades3 of Spades4 of Spades5 of Spades6 of Spades7 of Spades8 of Spades9 of Spades10 of SpadesJack of SpadesQueen of SpadesAce of Spades3 of Clubs

0 0
原创粉丝点击