Flipper
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 ≤ 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. Card 3 is a face up 4. |
Sample Input
5 |
Sample Output
Pile 1 |
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的更多相关文章
- Flipper & React Native
Flipper & React Native Flipper Flipper是一款用于调试移动应用程序的出色开发人员工具,在Android和iOS社区中颇受欢迎. Flipper is a g ...
- HDU 3328 Flipper 栈 模拟
首先想说,英语太烂这题读了很长时间才读懂......题意是说输入有几张牌,然后输入这些牌的初始状态(是面朝上还是面朝下),然后输入操作方式,R表示翻一下右边的牌堆,L表示翻一下左边的牌堆,直到最后摞成 ...
- HDU 3328 Flipper
题解:直接建n个栈,模拟过程即可…… #include <cstdio> #include <cstring> #include <stack> using nam ...
- HDU 3328 Flipper (stack)
最近着手打基础,做做STL的题目,虽然一般STL题目难度不大,但需要加快速度的准确率............................. 本题有N张牌,一开始每个位置一张(正面朝上或者朝下),有 ...
- [atAGC051C]Flipper
对于这一个平面用$a_{x,y}$来表示,即$(x,y)$为黑色则$a_{x,y}=1$,否则$a_{x,y}=0$,之后定义$a$能生成$b$当且仅当$a$能够通过若干次操作后得到$b$ 令$p_{ ...
- CSS3图片翻转切换案例及其中重要属性解析
图片翻转切换,在不使用CSS3的情况下,一般都是使用JS实现动画,同时操作元素的width和left,或者height和top以模拟翻转的效果,并在适当时候改变src或者z-index实现图片切换. ...
- Android开发自学笔记(Android Studio)—4.4 AdapterView及其子类
一.引言 AdapterView本身是一个抽象类,而它派生的子类在用法上也基本相似,只是在显示上有一定区别,因此把他们也归为一类. AdapterView具有如下特征: Ada ...
- css旋转
翻转180度 /* entire container, keeps perspective */ .flip-container { perspective: 1000; } /* flip the ...
- css动画属性性能
性能主要表现:流量.功耗与流畅度 在现有的前端动画体系中,通常有两种模式:JS动画与CSS3动画. JS动画是通过JS动态改写样式实现动画能力的一种方案,在PC端兼容低端浏览器中不失为一种推荐方案. ...
随机推荐
- DotNetCore跨平台~linux上还原自主nuget包需要注意的问题
问题的产生的背景 由于我们使用了jenkins进行部署(jenkins~集群分发功能和职责处理),而对于.net core项目来说又是跨平台的,所以对它的项目拉取,包的还原,项目的编译和项目的发布都是 ...
- You Are the One DP
You Are the One Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- Request.QueryString("id")与Request("id")区别
Request从几个集合取数据是有顺序的,从前到后的顺序依次是 QueryString,Form,最后是ServerVariables.Request对象按照这样的顺序依次搜索这几个集合中的变量,如果 ...
- java课程作业--动手动脑
随机数: 1)编写一个方法,使用以下算法生成指定数目(比如1000个)的随机整数. Modulus=231-1=int.MaxValue Multiplier=75=16807 C=0 当显示过231 ...
- HDU1257 最少拦截系统 (贪心+STL+二分)
第一次在博客园写博客,好紧张 .博客搬家居然很多代码成了乱码,欲哭无泪,妈咪. 开学东西太多了吧,没时间写备注,有点时候只能贴个代码,以后有时间再加备注吧,只贴代码不是好习惯. 咦,贪心怎么写,我只会 ...
- ZOJ2345Gold Coins 简单分块
昨天做过一样的题: 平方和公式:n*(n+1)*(2n+1) #include<cstdio> #include<cstdlib> #include<iostream&g ...
- Jquery实现鼠标移到某个对象,弹出显示层。
/** * 鼠标移上去显示层 * @param divId 显示的层ID * @returns */ $.fn.myHoverTip = function(divId) { var div = $(& ...
- 一个demo学会js
全栈工程师开发手册 (作者:栾鹏) 快捷链接: js系列教程1-数组操作全解 js系列教程2-对象和属性全解 js系列教程3-字符串和正则全解 js系列教程4-函数与参数全解 js系列教程5-容器和算 ...
- [置顶]
一个demo学会c#
学习了c#4.5高级编程这本书,自己喜欢边学边总结边写demo,所以写了这篇文章,包含了大部分的c#编程知识.让你一个demo掌握c#编程,如果有问题可以留言. 此demo主要包括五个文件:Stude ...
- 面试总结之mysql
总结自己在面试过程遇到的数据库问题,以备不时之需. 1.你在你们公司用的什么版本的mysql数据库,用过mysql5.7吗? 在学校学习mysql的时候用的5.5,在公司的时候用的5.6,5.7还真没 ...