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. ACM学习之路__HDU 1045

    Fire Net Description : Suppose that we have a square city with straight streets. A map of a city is ...

  2. JS(二)

    上周给大家介绍了一下JS基础中一点东西,今天给大家介绍一下JS基础中一个重要部分,循环和函数. 04-JS中的循环结构 一.[循环结构的步骤] 1.首先要先声明循环变量. 2.判断循环条件 3.执行循 ...

  3. taobao_api项目开坑,自主完成淘宝主要接口的开发-版本:卖家版(非淘宝api)

    项目名称:taobao_api 项目目的:独立实现各个淘宝操作的相关api,不依赖淘宝提供的api,而是自己实现接口 前期实现接口:已付款订单查询(自动更新), 订单发货 , 订单备注 应用场景:中小 ...

  4. Power Sum 竟然用原根来求

    Power Sum Time Limit: 20000/10000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitS ...

  5. LeetCode 650 - 2 Keys Keyboard

    LeetCode 第650题 Initially on a notepad only one character 'A' is present. You can perform two operati ...

  6. 项目收集-AutoMapper使用,事务,Json.Net序列化反序列化,代码生成调用等

    using System; using AutoMapper; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Console ...

  7. ionic构建APP--简单操作实现APP制作

    ionic--基于AngularJS的app框架 1安装ionic .HBuilder创建APP项目,导入ionic的css,js(fonts)文件. .导入ionic.css和ionic.bundl ...

  8. GooglePlay - 文件上传限制的扩展

    前言 Google Play应用商店在上传限制100MB大小,超过该大小的应用必须将超过部分以扩展文件的形式进行上传处理. 总共可上传2个扩展文件,每个最大文件可为2GB,同时obb文件格式可自选. ...

  9. servlet 相应头重定向

    package demoservllet; import java.io.IOException;import javax.servlet.ServletException;import javax. ...

  10. python学习记录-socket模块

    主要使用的模块是socket模块,在这个模块中可以找到socket()函数,该函数用于创建套接字对象.套接字也有自己的方法集,这些方法可以实现基于套接字的网络通信. 1.socket类型 构造函数: ...