博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Flipper
阅读量:7122 次
发布时间:2019-06-28

本文共 3871 字,大约阅读时间需要 12 分钟。

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.
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
5UUUDDRRLL5 1 2 3 4 510UUDDUUDDUULLLRRRLRL4 3 7 6 10
 
Sample Output
Pile 1Card 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 2Card 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
using namespace std;int n,m;int q;int Sym[110];//存储的每张牌的正反状态string Symbol[2]={
"up","down"};int l,r;//表示的是左右需要反转的指针;int ca=1;int card[110];//存储序列号码的顺序int tmp_card[110];//用来转移牌的中间数组string Frist_Symbol;//初始的所有牌的状态string Operation;//需要进行的操作void init(){ for(int i=0;i<=n;i++){ card[i]=i; } l=1;r=n;}void turn(char op,int &l,int &r){
//反转函数 if(op=='R'){
//翻右边的 // cout<<"翻右边"<
>Frist_Symbol; for(int i=0;i
>Operation; // cout<
<

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6366548.html

你可能感兴趣的文章
ubuntu设置静态IP
查看>>
hql select from与from 的区别
查看>>
wxPython之Socket客户端
查看>>
linux系统目录结构详解(简单易懂)
查看>>
学习《Effective C++》
查看>>
CS224n笔记9 机器翻译和高级LSTM及GRU
查看>>
KVM虚拟机
查看>>
GdiPlus[57]: 图像(九) IGPBitmap 特有的属性与方法
查看>>
Windows 多媒体函数(winmm.dll 中的函数)汇总
查看>>
关于 Delphi 中流的使用(4) 遍历读取流中的所有数据
查看>>
使用 IntraWeb (4) - 页面布局之 TIWRegion
查看>>
域控的升级及客户端加入域
查看>>
【Java每日一题】20161129
查看>>
[译文]greenlet:轻量级并发程序
查看>>
五分钟学会HTML
查看>>
请求Servlet 得到 Request 里所有对象
查看>>
volatile 和 synchronized 的比较
查看>>
Java递归
查看>>
windows 操作系统原版下载地址
查看>>
剑指offer——O(1)时间删除单链表节点
查看>>