UVA10205 - Stack 'em Up(模拟)
来源:互联网 发布:win10下装mac os双系统 编辑:程序博客网 时间:2024/05/19 03:19
UVA10205 - Stack 'em Up(模拟)
题目链接
题目大意:给你52张牌,这些牌一开始就有个顺序。现在给你每次的洗牌动作,52个数Ai,表示第i个位置上的牌放到Ai位置。意思就是能够通过这次洗牌,可以将i位置上的牌放到Ai位置上。至于后面的牌要不要移动什么的,根本不考虑。反正就是通过这次的洗牌,我给你52个数,把每个位置上的牌更新了一下。
解题思路:之前的题意看错,还以为是每次洗牌然后插入,后面才发现题意是这样的。那么只需要记录下上次洗牌的每个位置的牌,然后在将这次洗牌动作后的每个位置的牌更新,模拟洗牌,最后输出每个位置的牌。
代码:
#include <cstdio>#include <vector>using namespace std;const char Suit[4][10] = {"Clubs", "Diamonds", "Hearts", "Spades"};const char Value[13][10] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"};const int maxn = 105;int op[maxn][52];int d[52];struct card { int suit; int value; card(int suit = 0, int value = 0) { this->suit = suit; this->value = value; }};vector<card> v;void init () { for (int i = 0; i < 52; i++) d[i] = i; }void Operator (int K) { int c[52]; for (int i = 0; i < 52; i++) c[i] = d[op[K][i] - 1]; for (int i = 0; i < 52; i++) d[i] = c[i];}void output() { for (int i = 0; i < 52; i++) printf ("%s of %s\n", Value[v[d[i]].value], Suit[v[d[i]].suit]);}int main () { int T, N, K; char str[maxn]; scanf ("%d", &T); for (int i = 0; i < 4; i++) for (int j = 0; j < 13; j++) v.push_back(card(i, j)); while (T--) { scanf ("%d", &N); init(); for (int i = 0; i < N; i++) for (int j = 0; j < 52; j++) scanf ("%d", &op[i][j]); getchar(); while (gets(str) != NULL && str[0] != '\0') { sscanf (str, "%d", &K); Operator(K - 1); } output(); if (T) printf ("\n"); } return 0;}
0 0
- UVA10205 - Stack 'em Up(模拟)
- uva 10205 - Stack 'em Up(模拟)
- UVa 10205 Stack 'em Up (模拟)
- 110205 Stack 'em Up ( Stack em Up )
- UVA 10205 Problem E: Stack 'em Up(模拟)
- UVa 10205 Stack 'em Up
- uva 10205 Stack 'em Up
- UVA 10205 - Stack 'em Up
- UVa:10205 Stack 'em Up
- UVa 10205 Stack 'em Up
- UVa Problem Solution: 10205 - Stack 'em Up
- (挑战编程_2_5)Stack 'em Up
- programming-challenges Stack 'em Up (110205) 题解
- UVa Problem 10205 Stack ’em Up (完美洗牌术)
- 2.8.5 完美洗牌术 Stack 'em Up
- 31. Rack ‘Em Up
- PCB Stack-Up
- Protostar Stack Write Up
- offer那点事
- PB共享变量保持相同的值
- 想学写代码的产品经理
- 盒子模型主页实例
- 说与不说
- UVA10205 - Stack 'em Up(模拟)
- CocoaPods安装和使用教程
- 查看linux版本
- C#图片处理示例(裁剪,缩放,清晰度,水印)
- IOS开发---OC语言-㉗内存管理ARC的基本使用
- android:sharedUserId权限问题
- automake 用法
- 从现在开始就写博客
- jdbc-小结1