PC/UVA 110205/10205

水题。模拟

//author: CHC
//First Edit Time:  2014-01-22 13:06
//Last Edit Time:   2014-01-22 13:22
//Filename:1.cpp
#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
int type[120][60],n;
char value[13][10]={"2","3","4","5","6","7","8","9","10","Jack","Queen","King","Ace"
};
char suit[4][10]={"Clubs","Diamonds","Hearts","Spades"
};
struct p
{int val_num;char val[10];char suit[10];
}cs[53];
char t[1000];
void init(){int num=0;for(int i=0;i<4;i++){for(int j=0;j<13;j++){cs[++num].val_num=j;strcpy(cs[num].val,value[j]);strcpy(cs[num].suit,suit[i]);}}
}
void tran(int wh)
{p cs1[53]={ 0 };for(int i=1;i<=52;i++){int posi=type[wh][i],posj=i;cs1[posj]=cs[posi];}for(int i=1;i<=52;i++)cs[i]=cs1[i];
}
int main()
{int tt,flag=0;scanf("%d",&tt);while(tt--){if(flag)puts("");flag=1;scanf("%d",&n);for(int i=1;i<=n;i++)for(int j=1;j<=52;j++)scanf("%d",&type[i][j]);getchar();init();while(gets(t)!=NULL&&strcmp(t,"")!=0){int x;sscanf(t,"%d",&x);tran(x);}for(int i=1;i<=52;i++)printf("%s of %s\n",cs[i].val,cs[i].suit);}return 0;
}

Stack 'em Up

 

The Big City has many casinos. In one of them, the dealer cheats. She has perfected several shuffles; each shuffle rearranges the cards in exactly the same way whenever it is used. A 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 a sequence of shuffles.

A standard playing card deck contains 52 cards, with 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.

Input

The input begins with a single positive integer on a line by itself indicating the number of test cases, followed by a blank line. There is also a blank line between two consecutive inputs.

Each case consists of an integer n100, the number of shuffles that the dealer knows. Then follow n sets of 52 integers, each comprising 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. These indicate that you have observed the dealer applying the kth shuffle given in the input.

Output

For each test case, assume the dealer starts with a new deck ordered as described above. After all the shuffles had been performed, give the names of the cards in the deck, in the new order. The output of two consecutive cases will be separated by a blank line.

Sample Input

12
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

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

2.8.5 完美洗牌术 Stack 'em Up相关推荐

  1. UVa Problem 10205 Stack ’em Up (完美洗牌术)

    // Stack 'em Up (完美洗牌术) // PC/UVa IDs: 110205/10205, Popularity: B, Success rate: average Level: 1 / ...

  2. java 洗牌_java数组之完美洗牌算法

    题目详情 有个长度为2n的数组{a1,a2,a3,...,an,b1,b2,b3,...,bn},希望排序后{a1,b1,a2,b2,....,an,bn},请考虑有无时间复杂度o(n),空间复杂度0 ...

  3. 关于洗牌的研究(六)——从数学到魔术之完美洗牌

    爱学习,勤思考:学数学,玩魔术.欢迎点击头部蓝字关注MatheMagician,这里有你要的奇迹! 写再前面:本系列作品由MathMagician独家首发,一共有七篇,从数学和魔术两个角度对日常生活中 ...

  4. 完美洗牌问题(打乱数组间各元素的顺序)

    除了前一篇的完美洗牌问题,还有一种洗牌,就是乱序(shuffle)的问题,将54张有序的扑克牌的顺序打乱,实现洗牌操作. 局部洗牌法 1.随机产生一个1-n的数x,做为第一张牌. 2.随机产生一个1- ...

  5. java 完美洗牌,(2)数组相关算法题目

    数组是最简单的数据结构,占据连续内存并且按顺序存储. 以下是与数组有关的算法题目. (1)查询数组中重复数字 算法思路:(1)利用hash表,没有便放进去,有就返回(Java中HashMap存数字都是 ...

  6. 程序员编程艺术第三十四~三十五章:格子取数问题,完美洗牌算法

    第三十四~三十五章:格子取数,完美洗牌算法 作者:July.caopengcs.绿色夹克衫.致谢:西芹_new,陈利人, Peiyush Jain,白石,zinking. 时间:二零一三年八月二十三日 ...

  7. php 108张牌洗牌,完美洗牌原理大揭秘 手把手图文教程!呕心沥血的超级干货...

    原标题:完美洗牌原理大揭秘 & 手把手图文教程!呕心沥血的超级干货 先感慨一下,昨晚写到半夜,今天又修改了很多遍,我终于把这篇文章写完了. 然后自夸一下,我敢保证,你从来没有看过像这样的完美洗 ...

  8. 程序员编程艺术第三十四 三十五章 格子取数问题,完美洗牌算法

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 第三十四 ...

  9. 完美洗牌问题——核心思想与代码

    完美洗牌问题系列文章: 提示:很重要的思想 1.完美洗牌问题--整体交换数组的左右2部分 2.完美洗牌问题--计算位置i下次要被挤到哪个位置j? 这2个文章,都是为本文做铺垫的,循序渐进理解什么是完美 ...

最新文章

  1. jsp中九大内置对象
  2. 看完就能知道渗透测试的技术结构
  3. web前端 学习线路
  4. 好程序员HTML5前端教程-css的引入方式和选择器
  5. static--静态方法与静态成员
  6. FPGA积沙成塔(目录篇)
  7. 自动化通讯协定——现场总线
  8. shell基础之多功能nginx(安装、重启、停止等)
  9. python下载付费文档教程-用Python批量爬取付费vip数据,竟然如此简单
  10. 修改mysql密码后wordpress_修改数据库密码后,wordpress网站打不开
  11. java8中Lambda表达式写法详解
  12. 【群晖Nas开启WebDAV服务,路由器映射端口,实现Win10远程映射网路驱动器】
  13. 全网最详细的Intel CPU体系结构分析(内核源码)
  14. sam格式的结构和意义_SAM文件基础知识
  15. AS400 资料并分享面经一
  16. win7分区c盘调整容量_深度学习 | win7与ubuntu 18.04双系统安装教程
  17. MySQL函数计算24小时平均浓度对应的IAQI和AQI
  18. 微信二维码图片长按没有出现“识别图中的二维码”
  19. UDP通信,看我如何一步一步攻克面试官
  20. 抛出异常与栈展开(stack unwinding)

热门文章

  1. 币圈最全java入门教程+实战项目!
  2. 微信小程序自定义导航栏与自带下拉刷新冲突
  3. IDEA创建maven项目时的plugins、dependencies飘红问题
  4. android webview问题汇总
  5. php 对字母排序,PHP按字母顺序排序
  6. 如何赚到20万人民币
  7. 转载:Eb/No和SNR的区别
  8. 广东省地铁行业发展现状与动态前景评估报告2022版
  9. SECS/GEM 半导体设备通讯标准学习笔记
  10. eclipse如何导入jdk包