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. OC——继承

    继承的其中一个很重要的目的是为了实现多态.我们现在先来看看OC的继承. 一.继承 父类: 头文件 // // Peason.h // 01-继承和多态 // // Created by zhangji ...

  2. XtraGrid滚轮翻页

    滚轮翻页与传动的翻页更为方便,经过本人一番探讨与琢磨终于在XtraGrid的GridView中实现了鼠标滚轮翻页. 我新建了一个组件继承原本的GridControl,在组件中添加了一个ImageLis ...

  3. java中堆栈的功能作用 以及區別(搜集)

    1.用new创建的对象在堆区,函数中的临时变量在栈区,Java中的字符串在字符串常量区. 2.栈:存放进本数据类型的数据和对象的引用,但对象本身不存在栈中,而是存放在堆中.     堆:存放new产生 ...

  4. Pycharm中如何加载多个项目?

    今天在使用Pycharm工具练习Python时遇到一个疑问:在已存有项目A工程的前提下如何新建另一个项目B,且两者并存? 基本操作步骤: 在File下拉项中选择"New Project&qu ...

  5. hadoop(二)搭建伪分布式集群

    前言 前面只是大概介绍了一下Hadoop,现在就开始搭建集群了.我们下尝试一下搭建一个最简单的集群.之后为什么要这样搭建会慢慢的分享,先要看一下效果吧! 一.Hadoop的三种运行模式(启动模式) 1 ...

  6. python-实现一个贴吧图片爬虫

    今天没事回家写了个贴吧图片下载程序,工具用的是PyCharm,这个工具很实用,开始用的Eclipse,但是再使用类库或者其它方便并不实用,所以最后下了个专业开发python程序的工具,开发环境是Pyt ...

  7. 【转】Python-__builtin__与__builtins__的区别与关系(超详细,经典)

    在学习Python时,很多人会问到__builtin__.__builtins__和builtins之间有什么关系.百度或Google一下,有很 多答案,但是这些答案要么不准确,要么只说了一点点,并不 ...

  8. webpack 的使用1

    进入指定文件夹  npm init 安装 npm install webapck --save-dev 根目录下新建hello.js 将文件打包到指定文件  Asset :打包成的文件名称 Chunk ...

  9. 原生js反转字符串

    //直接操作 var str='nama';var rts=str.split('').reverse().join(''); //String上拓展方法String.prototype.revers ...

  10. 《阿里巴巴Java开发规约》插件使用介绍

    一.简介 阿里巴巴于10月14日在杭州云栖大会上,正式发布了<阿里巴巴Java开发规约>扫描插件!该插件基于<阿里巴巴Java开发规约>手册内容,在扫描代码后,将不符合规约的代 ...