HDU 3328

简介: Flipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 211    Accepted Submission(s): 135 Problem Description Little Bobby Roberts

Flipper

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 211    Accepted Submission(s): 135


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 of  n 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 form  m 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.
 

Source


#include <stack>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
struct node
{
    char status;
    int val;
} node1,node2;
stack <node>st[105];
char str1[105],str2[105];
node ans[110];
int n;
void init ()
{
    for (int i = 1; i <= n; i++)
    {
        node1.status = str1[i-1];
        node1.val = i;
        st[i].push (node1);
    }
}
int main ()
{
    int pile = 1;
    while (scanf ("%d\n",&n) != EOF && n!=0)
    {
        gets (str1);
        gets (str2);
        printf ("Pile %d\n",pile++);
        for (int i = 0; i <= n; i++ )
            while (!st[i].empty())
                st[i].pop();
            init ();
            int len = strlen (str2);
            int l = 1,r = n;
            for (i = 0; i < len; i++)
            {
                if (str2[i] == 'R')
                {
                    while (!st[r].empty ())
                    {
                        node1 = st[r].top ();
                        if (node1.status == 'D')
                            node1.status = 'U';
                        else node1.status = 'D';
                        st[r].pop ();
                        st[r-1].push (node1);
                    }
                    r--;
                }
                else
                {
                    while (!st[l].empty ())
                    {
                        node1 = st[l].top ();
                        if (node1.status == 'D')
                            node1.status = 'U';
                        else node1.status = 'D';
                        st[l].pop ();
                        st[l+1].push (node1);
                    }
                    l++;
                }
            }
            int k = 1;
            while (!st[l].empty ())
            {
                node1 = st[l].top ();
                st[l].pop ();
                ans[k++] = node1;
            }
            int m;
            int kk;
            scanf ("%d",&m);
            for ( i = 0; i < m; i++)
            {
                scanf ("%d",&kk);
                printf ("Card %d is a face ",kk);
                if (ans[kk].status == 'D')
                    printf ("down ");
                else printf ("up ");
                printf ("%d.\n",ans[kk].val);
            }
    }
    return 0;
}


目录
相关文章
Vue3组件库 -- element plus 树形选择器组件怎样显示已有的树形菜单?
Vue3组件库 -- element plus 树形选择器组件怎样显示已有的树形菜单?
268 0
|
机器学习/深度学习 达摩院 监控
最新开源!达摩院发布联邦学习框架FederatedScope
最新开源!达摩院发布联邦学习框架FederatedScope
465 0
|
人工智能 自然语言处理 小程序
6款AI写作工具类网站推荐
我们搜集了一些AI写作工具,希望对你有帮助,不论是在提升工作效率方面,还是在了解最新的AI技术方面,帮助你提升工作效率。
1838 0
|
弹性计算 负载均衡 Ubuntu
|
4天前
|
云安全 人工智能 安全
AI被攻击怎么办?
阿里云提供 AI 全栈安全能力,其中对网络攻击的主动识别、智能阻断与快速响应构成其核心防线,依托原生安全防护为客户筑牢免疫屏障。
|
14天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
8天前
|
安全 Java Android开发
深度解析 Android 崩溃捕获原理及从崩溃到归因的闭环实践
崩溃堆栈全是 a.b.c?Native 错误查不到行号?本文详解 Android 崩溃采集全链路原理,教你如何把“天书”变“说明书”。RUM SDK 已支持一键接入。
570 211
|
4天前
|
编解码 Linux 数据安全/隐私保护
教程分享免费视频压缩软件,免费视频压缩,视频压缩免费,附压缩方法及学习教程
教程分享免费视频压缩软件,免费视频压缩,视频压缩免费,附压缩方法及学习教程
229 138