UVA10205 POJ2469 ZOJ1896 Stack ‘em Up水题

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10205 POJ2469 ZOJ1896 Stack ‘em Up水题相关的知识,希望对你有一定的参考价值。

Stack 'em Up
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1130 Accepted: 411

Description

A standard playing card deck contains 52 cards, 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.
The Big City has many Casinos. In one such casino the dealer is a bit crooked. She has perfected several shuffles; each shuffle rearranges the cards in exactly the same way whenever it is used. A very 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 each in a sequence of shuffles.

Input

Input consists of an integer n <= 100, the number of shuffles that the dealer knows. 52n integers follow. Each consecutive 52 integers will comprise 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 indicating that you have observed the dealer applying the kth shuffle given in the input.

Output

Assume the dealer starts with a new deck ordered as described above. After each shuffle, give the names of the cards in the deck, in the new order, followed by an empty line.

Sample Input

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

Sample Output

3 of Clubs
2 of Clubs
4 of Clubs
5 of Clubs
6 of Clubs
7 of Clubs
8 of Clubs
9 of Clubs
10 of Clubs
Jack of Clubs
Queen of Clubs
King of Clubs
Ace of Clubs
2 of Diamonds
3 of Diamonds
4 of Diamonds
5 of Diamonds
6 of Diamonds
7 of Diamonds
8 of Diamonds
9 of Diamonds
10 of Diamonds
Jack of Diamonds
Queen of Diamonds
King of Diamonds
Ace of Diamonds
2 of Hearts
3 of Hearts
4 of Hearts
5 of Hearts
6 of Hearts
7 of Hearts
8 of Hearts
9 of Hearts
10 of Hearts
Jack of Hearts
Queen of Hearts
King of Hearts
Ace of Hearts
2 of Spades
3 of Spades
4 of Spades
5 of Spades
6 of Spades
7 of Spades
8 of Spades
9 of Spades
10 of Spades
Jack of Spades
Queen of Spades
Ace of Spades
King of Spades

King of Spades
2 of Clubs
4 of Clubs
5 of Clubs
6 of Clubs
7 of Clubs
8 of Clubs
9 of Clubs
10 of Clubs
Jack of Clubs
Queen of Clubs
King of Clubs
Ace of Clubs
2 of Diamonds
3 of Diamonds
4 of Diamonds
5 of Diamonds
6 of Diamonds
7 of Diamonds
8 of Diamonds
9 of Diamonds
10 of Diamonds
Jack of Diamonds
Queen of Diamonds
King of Diamonds
Ace of Diamonds
2 of Hearts
3 of Hearts
4 of Hearts
5 of Hearts
6 of Hearts
7 of Hearts
8 of Hearts
9 of Hearts
10 of Hearts
Jack of Hearts
Queen of Hearts
King of Hearts
Ace of Hearts
2 of Spades
3 of Spades
4 of Spades
5 of Spades
6 of Spades
7 of Spades
8 of Spades
9 of Spades
10 of Spades
Jack of Spades
Queen of Spades
Ace of Spades
3 of Clubs

Source

Waterloo local 2001.09.29

问题链接UVA10205 Stack 'em Up
问题简述:(略)
问题分析:计算问题,不解释。POJ和ZOJ的数据输入输出格式与UVA略微不同。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C语言程序(UVA)如下:

/* UVA10205 Stack 'em Up */

#include <stdio.h>

const char value[13][10] = "2", "3", "4", "5", "6", "7", "8", "9", "10",
                      "Jack", "Queen", "King", "Ace";
const char suit[4][10] = "Clubs", "Diamonds", "Hearts", "Spades";

#define N52 52
#define N 100
int shuffle[N + 1][N52 + 1], card[N52 + 1], t[N52 + 1];
char s[N];

void process(int id)

    for (int i = 1; i <= N52; i++)
        t[i] = card[shuffle[id][i]];
    for (int i = 1; i <= N52; i++)
        card[i] = t[i];


int main()

    int t, n;
    scanf("%d", &t);
    while (t--) 
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= N52; j++)
                scanf("%d", &shuffle[i][j]);

        for (int i = 1; i <= N52; i++) card[i] = i;

        int id;
        getchar();
        while (gets(s) && s[0]) 
            sscanf(s, "%d", &id);
            process(id);
        

        for (int i = 1; i <= N52; i++) 
            int k = card[i] - 1;
            printf("%s of %s\\n", value[k % 13], suit[k / 13]);
        
        if (t) putchar('\\n');
    

    return 0;

AC的C语言程序(POJ和ZOJ)如下:

/* POJ2469 ZOJ1896 Stack 'em Up */

#include <stdio.h>

const char value[13][10] = "2", "3", "4", "5", "6", "7", "8", "9", "10",
                      "Jack", "Queen", "King", "Ace";
const char suit[4][10] = "Clubs", "Diamonds", "Hearts", "Spades";

#define N52 52
#define N 100
int shuffle[N + 1][N52 + 1], card[N52 + 1], t[N52 + 1];
char s[N];

int main()

    int n;
    while (~scanf("%d", &n)) 
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= N52; j++)
                scanf("%d", &shuffle[i][j]);

        for (int i = 1; i <= N52; i++) card[i] = i;

        int id;
        while (~scanf("%d", &id) && id) 
            for (int i = 1; i <= N52; i++)
                t[i] = card[shuffle[id][i]];
            for (int i = 1; i <= N52; i++)
                card[i] = t[i];

            for (int i = 1; i <= N52; i++) 
                int k = card[i] - 1;
                printf("%s of %s\\n", value[k % 13], suit[k / 13]);
            

            putchar('\\n');
        
    

    return 0;

以上是关于UVA10205 POJ2469 ZOJ1896 Stack ‘em Up水题的主要内容,如果未能解决你的问题,请参考以下文章

UVA542 POJ2261 ZOJ1950 France ‘98概率

UVA10670 POJ1907 ZOJ2372 Work Reduction贪心

UVA10081 POJ2537 ZOJ1883 Tight WordsDP

UVA10277 POJ2646 ZOJ1856 Boastin‘ Red Socks数学

POJ2689 ZOJ1842 UVA10140 Prime Distance筛选法

POJ2351 ZOJ1916 UVA10371 Time Zones时区计算