B1042 Shuffling Machine(模拟扑克洗牌)

B1042 Shuffling Machine (20分)

  • 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.

给定的顺序是[1,54]中不同整数的排列。如果第i个位置的数字是j,则意味着将卡从位置i移动到位置j。

其实就是类似于扑克牌的洗牌,把[1,54]对应的牌连按给的位置序列连续移K次,中间的两重循环脑子烧了写了毛半个小时🤦‍,边界处也不是处理得很好,又臭又长,打表两分钟就初始化好了。

太晚了,脑子烧了,晚安(  ̄ o  ̄ ) . z Z

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const int MAX=100005;
const int INF=0x3f3f3f3f;
const int mod=1000000007;
char a[6][15][10];
map<int,int>mp;
void init()
{
    for(int j=1;j<=4;j++)
{
    for(int i=1;i<=13;i++)
    {
        char t;
        if(j==1)
            t='S';
        else if(j==2)
            t='H';
        else if(j==3)
            t='C';
        else if(j==4)
            t='D';
        a[j][i][0]=t;
        if(i>=10)
        {
        a[j][i][1]=i/10+'0';
        a[j][i][2]=i%10+'0';
        }
        else
        {
        a[j][i][1]=i+'0';
        }
    }
}

     for(int i=1;i<=2;i++)
        {
        a[5][i][0]='J';
        a[5][i][1]=i+'0';
        }
}
int main()
{
     init();
     int n,num1[55],num2[55];
     scanf("%d",&n);
     for(int i=1;i<=54;i++)
     {
         scanf("%d",&num1[i]);
     }
     for(int i=1;i<=54;i++)
     {
         num2[i]=i;
     }
     for(int j=0;j<n;j++)
     {
         for(int i=1;i<=54;i++)
         {
         mp[num1[i]]=num2[i];
         }
         for(int i=1;i<=54;i++)
         {
         num2[i]=mp[i];
         }
     }
     for(int i=1;i<=54;i++)
     {
         int tempx,tempy;
         if(num2[i]%13!=0)
         {
             tempx=num2[i]/13+1;
             tempy=num2[i]%13;
         }
         else
         {
             tempx=num2[i]/13;
             tempy=13;
         }
        if(i==1)
            cout<<a[tempx][tempy];
        else
            cout<<" "<<a[tempx][tempy];
     }
     return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值