pat 1042

1042. Shuffling Machine (20)

时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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.

Sample 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
Sample 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

//这道题虽然不难,但是刚开始做的时候,总想着把S1,S2,...存起来,之后再按照题目中的要求进行交换。
//如果发现把某些东西存起来困难时,这个东西若在输入中时唯一的,便可以用下标或者数字来表示。
//我还是太弱了啊。
#include <stdio.h>

int map[] = {'S', 'H', 'C', 'D', 'J'};
int main()
{
	int a[55], i, n, b[55], tmp[55];

	for(i = 1; i <= 54; i++)
		a[i] = i;

	scanf("%d", &n);

	for(i = 1; i <= 54; i++)
		scanf("%d", &b[i]);

	while(n--)
	{
		for(i = 1; i <= 54; i++)
			tmp[b[i]] = a[i];

		for(i = 1; i <= 54; i++)
			a[i] = tmp[i];
	}

	for(i = 1; i <= 54; i++)
	{
		printf("%c", map[(a[i] - 1)/13]);

		if(a[i] % 13 == 0)
			printf("%d", 13);
		else
			printf("%d", a[i]%13);
		if(i != 54)
			printf(" ");
		else
			printf("\n");
	}
	return 0;
}


在信息技术领域,"PAT" 是一个常见的缩写,通常指 **端口地址转换(Port Address Translation)**。这是一种网络地址转换(NAT)的形式,允许内部网络中的多个设备共享一个公共IP地址进行互联网通信。PAT 通过分配不同的端口号来区分来自不同内部设备的流量,从而实现地址的复用。这种方式不仅节省了IPv4地址资源,还增强了内部网络的安全性,因为外部网络无法直接访问内部网络中的具体设备[^1]。 ### 工作原理 在 PAT 过程中,当内部网络中的设备发起对外连接时,路由器或防火墙会记录下该设备的私有 IP 地址和端口号,并将其转换为公共 IP 地址和一个新的唯一端口号。当外部响应返回时,设备会根据端口号将数据包转发回正确的内部设备。这种机制在家庭宽带和企业网络中广泛使用,以确保多个用户可以共享一个公网 IP 地址上网。 ### 示例配置 以下是一个简单的 Cisco 路由器上配置 PAT 的示例命令: ```bash Router(config)# interface fa0/0 Router(config-if)# ip address 192.168.1.1 255.255.255.0 Router(config-if)# exit Router(config)# interface fa0/1 Router(config-if)# ip address 203.0.113.45 255.255.255.0 Router(config-if)# exit Router(config)# ip nat inside source list 1 interface fa0/1 overload Router(config)# access-list 1 permit 192.168.1.0 0.0.0.255 Router(config)# interface fa0/0 Router(config-if)# ip nat inside Router(config-if)# exit Router(config)# interface fa0/1 Router(config-if)# ip nat outside ``` ### 其他含义 除了端口地址转换外,"PAT" 在不同上下文中也可能有其他含义。例如,在软件开发中,PAT 可能指 **Personal Access Token**,这是一种用于身份验证的令牌,常用于访问 GitHub 等代码托管平台的 API。此外,在无线通信领域,PAT 可能代表 **Packet Arrival Time**,用于描述数据包到达的时间戳信息。 ### 应用场景 PAT 技术广泛应用于各种网络环境中,特别是在 IPv4 地址资源紧张的情况下。它不仅解决了地址不足的问题,还为内部网络提供了一定程度的安全保护。在云计算和虚拟化环境中,PAT 也常用于为虚拟机分配网络地址,确保它们可以正常访问外部网络。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值