日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 3328】Flipper (栈模拟)

發布時間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 3328】Flipper (栈模拟) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:
?

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 ofn?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 formm 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

?

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.

解題報告:

? ? ?直接進行棧模擬。

AC代碼:

#include<bits/stdc++.h>using namespace std; int n; char s[105]; int ans[105]; bool bk[105]; map<int ,string> mp; int main() {int iCase = 0;mp[0] = "down";mp[1] = "up";while(~scanf("%d",&n)) {if(n == 0) break;stack<int> sk[105];int l=1,r=n;for(int i = 1; i<=n; i++) sk[i].push(i);scanf("%s",s);for(int i = 0; i<n; i++) {bk[i+1] = s[i] == 'U' ? 1 :0 ;//朝上就是1,朝下就是0 }scanf("%s",s);for(int i = 0; i<n-1; i++) {if(s[i] == 'L') {l++;int size = sk[l-1].size();for(int j = 1; j<=size; j++) {int tmp = sk[l-1].top();sk[l-1].pop();bk[tmp] = !bk[tmp];sk[l].push(tmp);}}else {r--;int size = sk[r+1].size();for(int j = 1; j<=size; j++) {int tmp = sk[r+1].top();sk[r+1].pop();bk[tmp] = !bk[tmp];sk[r].push(tmp); }}}int top = 0; // printf("\n%d *** %d\n",l,r);while(!sk[r].empty()) {int tmp = sk[r].top();sk[r].pop();ans[++top] = tmp;}//for(int i = 1; i<=top; i++) printf("%d ",ans[i]);int q;scanf("%d",&q);printf("Pile %d\n",++iCase);while(q--) {int tmp;scanf("%d",&tmp);printf("Card %d is a face ",tmp);cout << mp[bk[ans[tmp]]]<<" "<<ans[tmp]<<".\n";}}return 0 ; }

?

總結

以上是生活随笔為你收集整理的【HDU - 3328】Flipper (栈模拟)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。