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端兼容低端浏览器中不失为一种推荐方案. ...
随机推荐
- Java多线程Runnable与Callable区别与拓展
我们先来分别看一下这两个接口 Runnable: // // Source code recreated from a .class file by IntelliJ IDEA // (powered ...
- C#ZIP根据路径读取压缩包内文件数量
/// <summary> /// 根据压缩包路径读取此压缩包内文件个数 /// </summary> /// <param name="strAimPath& ...
- linux debian 9 配置postgresSQL数据库
#读者注意:本文可以选择不看解释,直接执行每段的0中的代码 (〇):一些概念(可以跳过直接使用(一)0的代码) 1. 客户端:psql.postgreSQL的命令行客户端程序,在终端输入psql进入p ...
- hdu 1542 线段树 求矩形并
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- 126邮箱发送邮件python实现
126邮箱发送邮件python实现 from email.mime.text import MIMEText from email.utils import formataddr import smt ...
- POJ 2472 106 miles to Chicago(Dijstra变形——史上最坑的最长路问题)
题目链接 :http://poj.org/problem?id=2472 Description In the movie "Blues Brothers", the orphan ...
- python数据结构之栈与队列
python数据结构之栈与队列 用list实现堆栈stack 堆栈:后进先出 如何进?用append 如何出?用pop() >>> >>> stack = [3, ...
- 关于ios11 tableView和ScrollView受导航栏影响向下偏移的问题
看到网上说法ios11中automaticallyAdjustsScrollViewInsets属性被废弃,所以要设置tableView.contentInsetAdjustmentBehavior ...
- Python实战之IO多路复用select实例
Select方法: 句柄列表11, 句柄列表22, 句柄列表33 = select.select(句柄序列1, 句柄序列2, 句柄序列3, 超时时间) 参数: 可接受四个参数(前三个必须) 返回值 ...
- Python实战之实现简单的登陆系统-作业
#!usr/bin/env Python3 # -*-coding:utf-8-*- #编写登陆接口 #输入用户名密码 #认证成功后显示欢迎信息 #输错三次后锁定 __author__="W ...