Flipper

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 65 Accepted Submission(s): 52
 
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 ≤ qin. 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
East Central North America 2009
 
Recommend
teddy
 
/*
题意:阅读题题目有点坑,实际上就是模拟了一个翻牌的过程,首先n张牌平铺在桌面上的,没有重叠,每张给出正反面的状态
,然后有两种操作:R表示把最右边的一摞牌整体反转,全部放在右边第2张的牌上,L操作就是和R操作类似的,就是相反。
然后给出m次询问,问第i张牌的正反状态和翻转的次数
初步思路:模拟队列嘛,题意想出来了,就差不多了。操作最坏的情况是1e6,查询建一个映射就可以了 #错误:读错题了,不是反转次数,而是从上往下数是第q张牌,是几号牌,并且正反状态
反转的地方写的不对。 #感悟:调了两个小时的错,终于没辜负我,1Y
*/
#include<bits/stdc++.h>
using namespace std;
int n,m;
int q;
int Sym[];//存储的每张牌的正反状态
string Symbol[]={"up","down"};
int l,r;//表示的是左右需要反转的指针;
int ca=;
int card[];//存储序列号码的顺序
int tmp_card[];//用来转移牌的中间数组
string Frist_Symbol;//初始的所有牌的状态
string Operation;//需要进行的操作
void init(){
for(int i=;i<=n;i++){
card[i]=i;
}
l=;r=n;
}
void turn(char op,int &l,int &r){//反转函数
if(op=='R'){//翻右边的
// cout<<"翻右边"<<endl;
//每张牌进行反转
for(int i=r;i<=n;i++){
Sym[card[i]]^=;
}
//将这摞牌整过反转
for(int i=r;i<=(r+n)/;i++){
//cout<<card[i]<<" "<<card[n-(i-r)]<<endl;
int tmp=card[i];
card[i]=card[n-(i-r)]; //#出错 #修复 #再次修复 应该是n-(i-r)
card[n-(i-r)]=tmp; }
// for(int i=1;i<=n;i++){
// cout<<card[i]<<" ";
// }
// cout<<endl;
//将这摞牌放到r-1张牌的上边
/*
#错误:这里不应该是放在r-1,而是放在左边第一堆的上面 只有最后一次的时候才是将两堆放在一块
*/
if(l+!=r){//不是最后一次
int tmp=card[r-];
for(int i=r-;i<=n-;i++){
card[i]=card[i+];
}
card[n]=tmp;
}else{ //#出错
//最后一次
for(int i=;i<=l;i++){
tmp_card[i]=card[i];
}//中间专业数组
//cout<<"ok"<<endl;
for(int i=r;i<=n;i++){ //#手残 i写成了r
card[i-r+]=card[i];
}
//cout<<"ok"<<endl;
for(int i=(n-r+);i<=n;i++){
//cout<<i<<" "<<i-(n-r+2)+1<<endl;
card[i]=tmp_card[i-(n-r+)+];
}
}
// for(int i=1;i<=n;i++){
// cout<<card[i]<<" ";
// }
// cout<<endl;
r--;
}else{//翻左边的
//cout<<"翻左边"<<endl;
//每张牌进行反转
for(int i=;i<=l;i++){
Sym[card[i]]^=;
}
//将这摞牌整过反转
for(int i=;i<=(+l)/;i++){
int tmp=card[i];
card[i]=card[l-i+];
card[l-i+]=tmp;
}
//将这摞牌放到l+1张牌的上边
/*
#错误:这里不应该是放在l+1,而是放在右边第一堆的上面 只有最后一次的时候才是将两堆放在一块,放在一起实际上就是没有变化
*/
l++;
}
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF&&n){
getchar();
init();
printf("Pile %d\n",ca++);
cin>>Frist_Symbol;
for(int i=;i<Frist_Symbol.size();i++){//将没张牌的状态装到数组中
Sym[i+]=Frist_Symbol[i]=='U'?:;
}
// for(int i=1;i<=n;i++){
// cout<<Sym[i]<<" ";
// }
// cout<<endl;
cin>>Operation;
// cout<<Operation<<endl;
for(int i=;i<Operation.size();i++){
turn(Operation[i],l,r); // for(int i=1;i<=n;i++){
// cout<<Sym[i]<<" ";
// }
// cout<<endl;
//cout<<l<<" "<<r<<endl;
// for(int i=1;i<=n;i++){
// cout<<card[i]<<" ";
// }
// cout<<endl;
}
scanf("%d",&m);
while(m--){
scanf("%d",&q);
cout<<"Card "<<q<<" is a face "<<Symbol[Sym[card[q]]]<<" "<<card[q]<<".\n";
}
}
return ;
}

Flipper的更多相关文章

  1. Flipper & React Native

    Flipper & React Native Flipper Flipper是一款用于调试移动应用程序的出色开发人员工具,在Android和iOS社区中颇受欢迎. Flipper is a g ...

  2. HDU 3328 Flipper 栈 模拟

    首先想说,英语太烂这题读了很长时间才读懂......题意是说输入有几张牌,然后输入这些牌的初始状态(是面朝上还是面朝下),然后输入操作方式,R表示翻一下右边的牌堆,L表示翻一下左边的牌堆,直到最后摞成 ...

  3. HDU 3328 Flipper

    题解:直接建n个栈,模拟过程即可…… #include <cstdio> #include <cstring> #include <stack> using nam ...

  4. HDU 3328 Flipper (stack)

    最近着手打基础,做做STL的题目,虽然一般STL题目难度不大,但需要加快速度的准确率............................. 本题有N张牌,一开始每个位置一张(正面朝上或者朝下),有 ...

  5. [atAGC051C]Flipper

    对于这一个平面用$a_{x,y}$来表示,即$(x,y)$为黑色则$a_{x,y}=1$,否则$a_{x,y}=0$,之后定义$a$能生成$b$当且仅当$a$能够通过若干次操作后得到$b$ 令$p_{ ...

  6. CSS3图片翻转切换案例及其中重要属性解析

    图片翻转切换,在不使用CSS3的情况下,一般都是使用JS实现动画,同时操作元素的width和left,或者height和top以模拟翻转的效果,并在适当时候改变src或者z-index实现图片切换. ...

  7. Android开发自学笔记(Android Studio)—4.4 AdapterView及其子类

    一.引言       AdapterView本身是一个抽象类,而它派生的子类在用法上也基本相似,只是在显示上有一定区别,因此把他们也归为一类.       AdapterView具有如下特征: Ada ...

  8. css旋转

    翻转180度 /* entire container, keeps perspective */ .flip-container { perspective: 1000; } /* flip the ...

  9. css动画属性性能

    性能主要表现:流量.功耗与流畅度 在现有的前端动画体系中,通常有两种模式:JS动画与CSS3动画. JS动画是通过JS动态改写样式实现动画能力的一种方案,在PC端兼容低端浏览器中不失为一种推荐方案. ...

随机推荐

  1. Thinkphp5.0 在自己定义一个公共方法的控制器并且继承了Controller类的时候报错

    在建立网站的时候,你通常想着把一些共有的方法提取出来,放入一个控制器内,如果你是将业务逻辑写入了构造函数里面,那么就得注意了. 在thinkphp5.0当中,有一个初始化的方法,类似于构造函数,那就是 ...

  2. String的replace和replaceAll

    replace(CharSequence target, CharSequence replacement) 这里CharSequence是一个接口 实现类包括CharBuffer, Segement ...

  3. Linux - 设置/取消代理

    export http_proxy=118.210.42.251:44367 或: export https_proxy=118.210.42.251:44367   要取消该设置: unset ht ...

  4. httpd2.2配置文件详解

    httpd2.2官方配置手册:http://httpd.apache.org/docs/2.2/ 注意:关闭防火墙,iptables规则 vim /etc/sysconfig/selinux SELI ...

  5. Next Greater Element I

    You are given two arrays (without duplicates) nums1 and nums2 where nums1's elements are subset of n ...

  6. 简单Elixir游戏服务器-安装Elixir

    用WebInstaller 安装半天也没下载成功文件. 改成直接下载erlang 和 elixir 预编译包了. 安装很简单,最后设置好环境变量. cmd 执行 elixir -v 最后顺便下载了个g ...

  7. MySQL Windows版安装详解

    一.下载MySQL MySQL官网https://dev.mysql.com提供了Windows下的安装版msi和解压版zip,其中均包含32和64位版本,mis版本与SqlServer安装基本一致N ...

  8. Asp.net中防止用户多次登录的方法

    在web开发时,有的系统要求同一个用户在同一时间只能登录一次,也就是如果一个用户已经登录了,在退出之前如果再次登录的话需要报错. 常见的处理方法是,在用户登录时,判断此用户是否已经在Applicati ...

  9. MVVM框架解析(一)

    花了一点时间看了一下微软开源MVVM代码,受义很多! 从代码整体上看,代码分为四大类, 从图中看不能明白我要表达的意思.显而意见!MainApplicationWindow.xaml是应用程序主窗口( ...

  10. Hibernate 学习笔记 - 2

    五.映射一对多关联关系 1. 单向多对一 即 单向 n-1 1)单向 n-1 关联只需从 n 的一端可以访问 1 的一端 ① 域模型: 从 Order 到 Customer 的多对一单向关联需要在Or ...