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;
}


目录
相关文章
|
开发工具 C语言 C++
CMake构建大型C/C++项目:跨平台设计与高级应用(二)
CMake构建大型C/C++项目:跨平台设计与高级应用
757 0
|
9月前
|
人工智能 缓存 安全
阿里云Tokens怎么收费?最新AI焕新季优惠活动专享万亿Tokens扶持,免费领取1728元代金券
阿里云Tokens按输入/输出分别计费,价格因模型、产品及区域而异,官方活动精准报价:https://t.aliyun.com/U/FzmsXA 千问-Plus约¥0.0008/千tokens(输入),通义点金高级版¥0.1/千tokens。现推出AI焕新季活动,享万亿Tokens扶持及1728元代金券,开通百炼更可免费领7000万Tokens!
1632 1
|
Kubernetes 负载均衡 Ubuntu
Kubernetes安装详细教程 Ubuntu版
本教程基于Ubuntu 22.04配置Kubernetes环境,涵盖依赖安装、swap关闭、内核参数调整、containerd与Kubernetes组件安装、集群初始化及CNI网络插件部署等内容,并提供常见问题处理方法和相关工具推荐。
|
JavaScript 前端开发 Java
编程之旅:从代码到哲学
【10月更文挑战第3天】在编程的海洋中,我们不仅仅是在编写代码,更是在探索生命的意义。从大学毕业时的迷茫,到大胆尝试新领域,再到不断学习和提升,我找到了人生的方向。正如乔布斯所说,“人生中的每一个点都会在未来某个时刻连接起来”。让我们一起踏上这段旅程,探索编程背后的哲理和生命的奥秘。
183 3
|
数据安全/隐私保护
Wiki.js 配置 LDAP 认证
Wiki.js 配置 LDAP 认证
|
运维 Kubernetes 安全
进阶课程:如何在 ACK 中使用 MSEIngress|学习笔记(一)
快速学习进阶课程:如何在 ACK 中使用 MSEIngress
进阶课程:如何在 ACK 中使用 MSEIngress|学习笔记(一)
|
前端开发
css自定义 range radio select的样式滑轮,按钮,选择框
写在前面: 之前踩坑css的时候,遇到滑轮,按钮,选择框这类型的东西,为了页面效果,总是需要自定义他们的样式,而不使用他们的默认样式。当时写的时候,我也是蛮头疼的,弄了个demo,链接在下面。对此做个总结。本文是面向前端小白的,大手子可以跳过,写的不好之处多多见谅。 额,今天就先大概的将代码贴上来,考虑到篇幅的问题,就先写一下三个的实现方式,一般也都看得懂,代码注释的非常详细。因为细分下来内容也很多,准备之后再将如何实现的方式,属性,优化以及如何兼容各个浏览器的方式一步步的写出来。 最终效果:
655 0
css自定义 range radio select的样式滑轮,按钮,选择框
|
机器学习/深度学习 人工智能 自动驾驶
震天的战鼓已经敲响,你在人工智能中处于哪个阵营?
每个人都知道人工智能是未来科技的方向,但每个人对于学 AI 都持有不同的态度。近日,Twitter 上有一张图火了,引来 Yann LeCun 等大牛、CSAIL at MIT 等账号争相转发。这张图把深度学习学者分为了四种人,描述了四种类型学习者的特征。机器之心读者们可以对号入座,看自己是 Cann YeLun 还是 LeiLei Fi。
364 0
震天的战鼓已经敲响,你在人工智能中处于哪个阵营?
成功解决VS编译环境下C++语言出现的异常提示:烫烫烫烫烫烫烫烫烫烫
成功解决VS编译环境下C++语言出现的异常提示:烫烫烫烫烫烫烫烫烫烫
成功解决VS编译环境下C++语言出现的异常提示:烫烫烫烫烫烫烫烫烫烫
|
消息中间件 弹性计算 Cloud Native
阿里云体验实验室教师开课操作手册
阿里云体验实验室支持高校教师开设云产品技术类或通用计算机技术类的实践类课程,提供标准化的实验环境和云产品资源,教师可以自定义教学内容,将理论教学与实践结合,快速实现Learn by Doing。
959 0
阿里云体验实验室教师开课操作手册