题干:

Problem Description

Little Bobby Roberts (son of Big Bob, of Problem G) plays this solitaire memory game called Flipper. He starts with n cards, numbered 1 through n, and lays them out in a row with the cards in order left-to-right. (Card 1 is on the far left; card n is on the far right.) Some cards are face up and some are face down. Bobby then performs n - 1 flips — either right flips or left flips. In a right flip he takes the pile to the far right and flips it over onto the card to its immediate left. For example, if the rightmost pile has cards A, B, C (from top to bottom) and card D is to the immediate left, then flipping the pile over onto card D would result in a pile of 4 cards: C, B, A, D (from top to bottom). A left flip is analogous.

The very last flip performed will result in one pile of cards — some face up, some face down. For example, suppose Bobby deals out 5 cards (numbered 1 through 5) with cards 1 through 3 initially face up and cards 4 and 5 initially face down. If Bobby performs 2 right flips, then 2 left flips, the pile will be (from top to bottom) a face down 2, a face up 1, a face up 4, a face down 5, and a face up 3.

Now Bobby is very sharp and you can ask him what card is in any position and he can tell you!!! You will write a program that matches Bobby’s amazing feat.

Input

Each test case will consist of 4 lines. The first line will be a positive integer n (2 ≤ n ≤ 100) which is the number of cards laid out. The second line will be a string ofn characters. A character U indicates the corresponding card is dealt face up and a character D indicates the card is face down. The third line is a string of n - 1 characters indicating the order of the flips Bobby performs. Each character is either R, indicating a right flip, or L, indicating a left flip. The fourth line is of the formm q1 q2 . . . qm, where m is a positive integer and 1 ≤ qi ≤ n. Each qi is a query on a position of a card in the pile (1 being the top card, n being the bottom card). A line containing 0 indicates end of input.

Output

Each test case should generate m + 1 lines of output. The first line is of the form

Pile t

where t is the number of the test case (starting at 1). Each of the next m lines should be of the form

Card qi is a face up k.

or

Card qi is a face down k.

accordingly, for i = 1, ..,m, where k is the number of the card.
For instance, in the above example with 5 cards, if qi = 3, then the answer would be

Card 3 is a face up 4.

Sample Input

 

5 UUUDD RRLL 5 1 2 3 4 5 10 UUDDUUDDUU LLLRRRLRL 4 3 7 6 1 0

Sample Output

 

Pile 1 Card 1 is a face down 2. Card 2 is a face up 1. Card 3 is a face up 4. Card 4 is a face down 5. Card 5 is a face up 3. Pile 2 Card 3 is a face down 1. Card 7 is a face down 9. Card 6 is a face up 7. Card 1 is a face down 5.

解题报告:

直接进行栈模拟。

AC代码:

#include<bits/stdc++.h>using namespace std;
int n;
char s[105];
int ans[105];
bool bk[105];
map<int ,string> mp;
int main()
{int iCase = 0;mp[0] = "down";mp[1] = "up";while(~scanf("%d",&n)) {if(n == 0) break;stack<int> sk[105];int l=1,r=n;for(int i = 1; i<=n; i++) sk[i].push(i);scanf("%s",s);for(int i =  0; i<n; i++) {bk[i+1] = s[i] == 'U' ? 1 :0 ;//朝上就是1,朝下就是0 }scanf("%s",s);for(int i = 0; i<n-1; i++) {if(s[i] == 'L') {l++;int size = sk[l-1].size();for(int j = 1; j<=size; j++) {int tmp = sk[l-1].top();sk[l-1].pop();bk[tmp] = !bk[tmp];sk[l].push(tmp);}}else {r--;int size = sk[r+1].size();for(int j = 1; j<=size; j++) {int tmp = sk[r+1].top();sk[r+1].pop();bk[tmp] = !bk[tmp];sk[r].push(tmp);  }}}int top = 0;
//      printf("\n%d ***  %d\n",l,r);while(!sk[r].empty()) {int tmp = sk[r].top();sk[r].pop();ans[++top] = tmp;}//for(int i = 1; i<=top; i++) printf("%d ",ans[i]);int q;scanf("%d",&q);printf("Pile %d\n",++iCase);while(q--) {int tmp;scanf("%d",&tmp);printf("Card %d is a face ",tmp);cout << mp[bk[ans[tmp]]]<<" "<<ans[tmp]<<".\n";}}return 0 ;
}

【HDU - 3328】Flipper (栈模拟)相关推荐

  1. HDU 3328 Flipper 栈 模拟

    HDU 3328 Flipper 栈 模拟 首先想说,英语太烂这题读了很长时间才读懂......题意是说输入有几张牌,然后输入这些牌的初始状态(是面朝上还是面朝下),然后输入操作方式,R表示翻一下右边 ...

  2. HDU 3328 Flipper 魔术纸牌

    原题 http://acm.hdu.edu.cn/showproblem.php?pid=3328 题目: Flipper Time Limit: 2000/1000 MS (Java/Others) ...

  3. 每日一套codeforce集训1119E[贪心],821C[栈模拟],645D[拓扑排序]

    有n种长度的棍子,长度分别为2^0 ,2 ^ 1,-,2 ^ (n-1) ,每种棍子有a[i] 种,问你能组成多少个三角形. 三角形两边之和大于第三边,而2 ^ i + 2 ^ i = 2 ^ (i+ ...

  4. P1944 最长括号匹配(栈模拟/DP)

    P1944 最长括号匹配 可以直接用栈模拟,把匹配好的标记一下, 最后找到最长的匹配输出即可. 如果是要求最长的长度的题那么只需要求数就行了,没必要把原序列真的按照题意改变 如果要求序列,那么只需要按 ...

  5. 【干货】容器适配器实现两个栈模拟队列

    用两个栈模拟队列的思想就是"倒水思想",这里我们用自定义类型模拟出线性表,再用线性表做容器实现栈的数据结构,最后用栈来实现队列,代码如下: #include<iostream ...

  6. Code POJ - 1780(栈模拟dfs)

    题意: 就是数位哈密顿回路 解析: 是就算了...尼玛还不能直接用dfs,得手动开栈模拟dfs emm...看了老大半天才看的一知半解 #include <iostream> #inclu ...

  7. 括号配对问题----栈模拟

    括号配对问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 现在,有一行括号序列,请你检查这行括号是否配对. 输入 第一行输入一个数N(0<N<=100), ...

  8. 227 用栈模拟汉诺塔问题

    原题网址:https://www.lintcode.com/problem/mock-hanoi-tower-by-stacks/description 描述 在经典的汉诺塔问题中,有 3 个塔和 N ...

  9. 栈模拟递归 遍历二叉树的正确写法

    栈模拟递归 遍历二叉树的正确写法 二叉树的生成 树的层次遍历 前中后序遍历的递归实现 关于栈的实现 Reference 对于二叉树的生成,遍历,应该是树这个数据结构需要的基本功,只有真的理解了树的生成 ...

  10. 基础算法4 —— 结构体(成绩统计) + 栈(模拟进制转换 + 优秀的拆分) + 指针

    结构体 结构体的实际应用场景: 在实际问题中,一组数据往往具有不同的数据类型.比如,某次期末考试中要记录一个学生的考试信息,除了有姓名(char)外,还有班级(int).性别(char).语文.数学. ...

最新文章

  1. Oracle 10g(10.2.0.4)升级到10.2.0.5.19
  2. python cv2模块安装_Python运行脚本前,自动安装需要的模块包
  3. spoj Balanced Numbers(数位dp)
  4. 学号20145209《信息安全系统设计基础》第11周学习总结
  5. 单元测试线程代码的5个技巧
  6. 前端学习(680):switch注意事项
  7. MATLAB中的S-Function的用法(C语言)
  8. gSoap客户端调用WebService完成后注意内存释放顺序
  9. 蔚来明年推出Gemini 该系列保持高端定位?
  10. tomcat catalina localhost 没有项目_Tomcat简介--01
  11. 公式化学习urllib(第一卷)
  12. IE10、IE11解决不能播放Flash的问题!
  13. 【解读】Http协议
  14. While 1比While True快?
  15. 图像识别的原理、过程、应用前景,精华篇!
  16. 深大与南科大计算机,深圳大学和南方科技大学你选哪所?哪所实力更强?
  17. MOSFet cutoff frequency ( From google)
  18. 2021,你值得看的华为/字节/腾讯/京东/网易/滴滴面经分享
  19. Blender游戏开发教程
  20. 两个构件的重合点_两构件形成移动副,则两构件重合点的相对速度一定沿移动方向。...

热门文章

  1. [剑指offer]面试题第[55-1]题[JAVA][二叉树的深度][BFS][DFS]
  2. [剑指offer]面试题第[38]题[JAVA][字符串的排列][回溯法]
  3. [Leedcode][JAVA][第94/144/145题][前中后序遍历][递归][迭代][二叉树]
  4. [Leedcode][JAVA][第50题][Pow(x, n)][快速幂][分治][转换类型]
  5. sublime配置python环境变量_Sublime Python环境配置
  6. python怎么读取github_六行代码获取Github排名前10的Python项目
  7. Java别说取余( )运算简单,你真的会吗
  8. Linux禁止ip拒绝访问80,Linux iptables 设置允许(禁止)IP范围
  9. linux last failed login表示什么意思_Linux用户
  10. Codeforces Round #719 (A-C)