PAT A1042 Shuffling Machine
自己思路,没通过
#include <cstdio>
#define N 54
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
int start[N + 1] = {0}, end[N + 1] = {0}, sequence[N + 1] = {0};
for(int i = 1; i < N + 1; i++) {//初始化牌的编号
start[i] = i+1;
}
int n;
scanf("%d", &n);//输入操作的次数
for(int i = 1; i < N + 1; i++) {//输入每个位置上的牌在操作后的位置
int n;
scanf("%d", &sequence[i]);
}
/*for(int i = 1; i < N; i++) {
printf("%d\n", sequence[i]);
}*/
for(int i = 0; i < n; i++) {//执行n次操作
for(int i = 1; i < N + 1; i++) {
end[sequence[i]] = start[i];
}
for(int i = 1; i < N + 1; i++) {
start[i] = end[i];
}
}
/*for(int i = 1; i < N + 1; i++) {
printf("%d\n", end[i]);
}
*/
for(int i = 1; i < N; i++) {
//printf("%d---", end[i]);
if(i != N) {
if(end[i] / 13 == 0) {
if(end[i] % 13 == 0) {
printf("S13 ");
} else {
printf("S%d ", end[i] % 13);
}
} else if(end[i] / 13 == 1) {
if(end[i] % 13 == 0) {
printf("H13 ");
} else {
printf("H%d ", end[i] % 13);
}
} else if(end[i] / 13 == 2) {
if(end[i] % 13 == 0) {
printf("C13 ");
} else {
printf("C%d ", end[i] % 13);
}
} else if(end[i] / 13 == 3) {
if(end[i] % 13 == 0) {
printf("D13 ");
} else {
printf("D%d ", end[i] % 13);
}
} else if(end[i] / 13 == 4) {
printf("J%d ", end[i] % 13);
}
} else {
if(end[i] / 13 == 0) {
if(end[i] % 13 == 0) {
printf("S13");
} else {
printf("S%d", end[i] % 13);
}
} else if(end[i] / 13 == 1) {
if(end[i] % 13 == 0) {
printf("H13");
} else {
printf("H%d", end[i] % 13);
}
} else if(end[i] / 13 == 2) {
if(end[i] % 13 == 0) {
printf("C13");
} else {
printf("C%d", end[i] % 13);
}
} else if(end[i] / 13 == 3) {
if(end[i] % 13 == 0) {
printf("D13");
} else {
printf("D%d", end[i] % 13);
}
} else if(end[i] / 13 == 4) {
printf("J%d", end[i] % 13);
}
}
}
return 0;
}
AC
#include <cstdio>
const int N = 54;
char mp[5] = {'S', 'H', 'C', 'D', 'J'};
int start[N+1], end[N+1], next[N+1];
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
int K;
scanf("%d", &K);
for(int i = 1; i <= N; i++) {
start[i] = i;
}
for(int i = 1; i <= N; i++) {
scanf("%d", &next[i]);
}
for(int step = 0; step < K; step++) {
for(int i = 1; i <= N; i++) {
end[next[i]] = start[i];
}
for(int i = 1; i <= N; i++) {
start[i] = end[i];
}
}
for(int i = 1; i <= N; i++) {
if(i != 1) printf(" ");
start[i]--;
printf("%c%d", mp[start[i] / 13], start[i] % 13 + 2);
}
return 0;
}
PAT A1042 Shuffling Machine的更多相关文章
- PAT甲级——A1042 Shuffling Machine
Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techn ...
- PAT 1042. Shuffling Machine (20)
1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shu ...
- A1042. Shuffling Machine
Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techn ...
- PAT 1042 Shuffling Machine[难]
1042 Shuffling Machine (20)(20 分) Shuffling is a procedure used to randomize a deck of playing cards ...
- A1042 Shuffling Machine (20)
1042 Shuffling Machine (20)(20 分) Shuffling is a procedure used to randomize a deck of playing cards ...
- pat 1042 Shuffling Machine(20 分)
1042 Shuffling Machine(20 分) Shuffling is a procedure used to randomize a deck of playing cards. Bec ...
- PAT 1042 Shuffling Machine (20 分)
1042 Shuffling Machine (20 分) Shuffling is a procedure used to randomize a deck of playing cards. ...
- PAT 1042 Shuffling Machine
#include <cstdio> #include <cstdlib> #include <vector> using namespace std; ] = {' ...
- PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...
随机推荐
- FPGA课设-基于Xilinx Basys2开发板的除法器设计
介绍一下Basys开发板: Basys2 FPGA开发板是一个电路设计实现平台,任何人都可以通过它来搭建一个真正的数字电路.Basys2是围绕着一个Spartan-3E FPGA芯片和一个Atmel ...
- Teamviewer14重置试用期版
网上的破解版基本上全部被封禁了,只能通过修改ID来无限试用这个方法了 有些个人使用频繁的用户,经常提示商业环境 此teamviewer14重置试用期,可以一直使用 有条件的还是建议购买付费版. 到期点 ...
- Django-CRM后台管理系统
crm整体流程 表结构 from django.db import models # Create your models here. from django.contrib.auth.models ...
- CF981D
CF981D 题意: 给你n个数,要求你分成k堆.每堆的内部加和,每堆之间是相与.问最大的值. 解法: 二进制下最大的数的所有位一定是1,所以贪心去找是否最大一定是正确的. 然后DP记录+贪心就可以A ...
- LNMP和LAMP的搭建
LNMP 环境:阿里云ubuntu 16 mysql: apt-get install mysql-server mysql-client php: apt-get install php-fpm p ...
- LeetCode 41. 缺失的第一个正数(First Missing Positive)
题目描述 给定一个未排序的整数数组,找出其中没有出现的最小的正整数. 示例 1: 输入: [1,2,0] 输出: 3 示例 2: 输入: [3,4,-1,1] 输出: 2 示例 3: 输入: [7,8 ...
- Android网络编程之——文件断点下载
一:关于断点下载所涉及到的知识点 1.对SQLite的增删改查(主要用来保存当前任务的一些信息) 2.HttpURLConnection的请求配置 HttpURLConnection connecti ...
- 解决ssh连接超时(ssh timeout)的方法
echo export TMOUT=1000000 >> /root/.bash_profile (可设置为-1为永不超时) cat /root/.bash_profile source ...
- Python的一个bug,记录一下
安装报错:E:\webpy-master>python setup.py installTraceback (most recent call last): File "setup.p ...
- 微服务的脚手架Jhipster使用(一)
随着微服务的普及以及docker容器的广泛应用,有传统的soa服务衍生出微服务的概念,微服务强调的是服务的独立性,屏蔽底层物理平台的差异,此时你会发现微服务跟容器技术完美契合.在此基础上衍生出的云原生 ...