A1042 Shuffling Machine (20 minutes | simple simulation, with detailed comments, logic analysis)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_24452475/article/details/100569875

EDITORIAL

  • Ideas analysis
    • Simple simulation
    • startsAnd endsan array of storage start and end of the sequence order of each linear transformation (in memory numbers 1 to 54)
    • The number of cards with alphanumeric correspondence relationship between the output endsarray
  • Problems
    • Subscript binary conversion,13
      • Details of the deal
  • Details of the process takes time, a title 25 minutes

Test Case

  • 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
    

ac Code

  • Reference links
    #include <cstdio>
    using namespace std;
    
    int main()
    {
        int cnt;
        scanf("%d", &cnt);
        int starts[55], ends[55], scan[55];
        // 存储输入
        for(int i=1; i<55; i++)
        {
            scanf("%d", &scan[i]);
            ends[i] = i;
        }
    
        for(int i=0; i<cnt; i++)
        {
            for(int j=1; j<55; j++)
                starts[j] = ends[j];
            for(int k=1; k<55; k++)
                ends[scan[k]] = starts[k];
        }
    
        char c[6] = {"SHCDJ"};
        for(int i=1; i<55; i++)
        {
    	    // 字母切换, 进制转换 [细节处理]
            printf("%c%d", c[(ends[i]-1)/13], (ends[i]-1)%13+1);
            if(i != 54) printf(" ");
        }
    
        return 0;
    }
    

Guess you like

Origin blog.csdn.net/qq_24452475/article/details/100569875