HDU 3328 Flipper(栈模拟)
来源:互联网 发布:linux acl权限控制 编辑:程序博客网 时间:2024/05/16 12:13
代码:
#include<stdio.h>#include<string.h>#include<stack>using namespace std;int t;int base[105];int temp[105]; //询问char ans[105];int flag[105];int main(){ int ui=1; while(~scanf("%d",&t)) { stack<int>G[105]; memset(base,0,sizeof(base)); memset(temp,0,sizeof(temp)); memset(flag,0,sizeof(flag)); if(t==0)break; getchar(); char x; memset(base,0,sizeof(base)); for(int i=1;i<=t;i++) { scanf("%c",&x); if(x=='U') base[i]=1; if(x=='D') base[i]=0; G[i].push(i); } getchar(); for(int i=1;i<=t-1;i++) { scanf("%c",&ans[i]); } getchar(); int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&temp[i]); } int l=1,r=t; /*for(int i=1;i<=t;i++) { printf("%d ",base[i]); } printf("\n");*/ for(int i=1;i<=t-1;i++) { //printf("%c\n",ans[i]); if(ans[i]=='R') { while(!G[r].empty()) { G[r-1].push(G[r].top()); if(base[G[r].top()]==0) base[G[r].top()]=1; else base[G[r].top()]=0; G[r].pop(); } r--; } if(ans[i]=='L') { while(!G[l].empty()) { G[l+1].push(G[l].top()); if(base[G[l].top()]==0) base[G[l].top()]=1; else base[G[l].top()]=0; G[l].pop(); } l++; } } /*for(int i=1;i<=t;i++) { printf("%d ",G[i].size()); }*/ /*for(int i=1;i<=t;i++) { printf("%d ",base[i]); }*/ int op[105],k=1; while(!G[l].empty()) { //printf("%d ",G[l].top()); op[k++]=G[l].top(); G[l].pop(); } printf("Pile %d\n",ui++); for(int i=0;i<n;i++) { printf("Card %d is a face ",temp[i]); // printf("%d ",base[op[temp[i]]]); if(base[op[temp[i]]]==0) { printf("down "); } else { printf("up "); } printf("%d.\n",op[temp[i]]); } }}
C - Flipper
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uAppoint description:
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.
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
For instance, in the above example with 5 cards, if qi = 3, then the answer would be
Pile twhere 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.
0 0
- HDU 3328 Flipper(栈模拟)
- HDU-3328-Flipper(栈模拟)
- hdu 3328 Flipper(栈模拟)
- HDU 3328 Flipper [模拟]
- hdu 3328 Flipper(栈)
- hdu 3328 Flipper 模拟题
- Flipper (栈模拟)
- hdu Flipper (用栈模拟)
- HDU 3328 Flipper (stack)
- Flipper(杭电3328)(模拟栈)
- HDU 3328 Flipper 栈的应用
- HDU 3328 Flipper(优先队列)
- hdu 3328 Flipper <stack>
- hdu 3328 Flipper
- hdu 3328 Flipper
- HDU 3328 Flipper 魔术纸牌
- Flipper(栈)
- hdu3328(Flipper)经典栈类
- HDU 1005 Number Sequence[数论]
- Servlet的调用过程和生命周期
- ios开发-获取手机相关信息
- python字典复制(浅拷贝and深拷贝)
- 物联网加密
- HDU 3328 Flipper(栈模拟)
- 剑指offer-6-面试43:n 个骰子的点数()
- deepin 系统中MongoDB的安装
- VC维
- SVN服务器和客户端的安装以及在MyEclipse中的配置
- fatal error C1004unexpected end of file found
- android proguard使用心得和遇到的若干问题以及解决思路
- 将Assets中所有目录和文件,都复制到SD卡中
- GuavaCache使用笔记