首页 > ACM题库 > HDU-杭电 > HDU 3328-Flipper-栈-[解题报告]HOJ
2014
03-16

HDU 3328-Flipper-栈-[解题报告]HOJ

Flipper

问题描述 :

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.

输入:

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.

输出:

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.

样例输入:

5
UUUDD
RRLL
5 1 2 3 4 5
10
UUDDUUDDUU
LLLRRRLRL
4 3 7 6 1
0

样例输出:

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.

#include<stdio.h>
#include<stack>
#include<string.h>
using namespace std;
stack<int> s[105];         //每张牌看成一个栈
int main()
{
  int n,m,num=1,i,j,a[105],k;
  char str[105];
  int ok[105];               //标记每张牌的状态
  while(scanf("%d",&n)!=EOF)
  { 
    if(n==0)
         break;
    scanf("%s",str);
    for(i=0;i<n;i++)
    {
       if(str[i]=='U')
           ok[i]=1;
       else
           ok[i]=0;
    }
    
    int l=0,r=n-1;
    for(i=0;i<n;i++)
        s[i].push(i);       
    scanf("%s",str);
    for(i=0;i<n-1;i++)
    {
       if(str[i]=='L')
       { 
         l++;
         for(j=0;j<l;j++)
             ok[j]=1-ok[j];
         while(!s[l-1].empty())
         {
             s[l].push(s[l-1].top());
             s[l-1].pop();
         }
       }
       else
       {
         r--;
         for(j=n-1;j>r;j--)
             ok[j]=1-ok[j];
         while(!s[r+1].empty())
         {
           s[r].push(s[r+1].top());
           s[r+1].pop();
         }
       }
    }
     for(i=0;i<n;i++)
     {
         a[i]=s[l].top();
         s[l].pop();
     }
     printf("Pile %d\n",num++);
     scanf("%d",&m);
     while(m--)
     {  
        scanf("%d",&k);
        printf("Card %d is a face ",k);  
        k--;  
        printf(ok[a[k]]?"up ":"down ");  
        printf("%d.\n",a[k]+1);  
     }
  }
  return 0;
}

参考:http://blog.csdn.net/steamqueen/article/details/7730304


  1. Pingback: best vibrator for couples

  2. Pingback: طراحی سایت توسط پویا وب

  3. Pingback: 8 oz tkd uniform

  4. Pingback: sex kit

  5. Pingback: نصب دوربین های مدار بسته

  6. Pingback: long dildo

  7. Pingback: over shoes

  8. Pingback: خرید اپل ایدی

  9. Pingback: Magnet tape

  10. Pingback: {دوربین مداربسته|دوربین مداربسته سامسونگ|

  11. Pingback: gay lubricants

  12. Pingback: کفسابی

  13. Pingback: مشاوره با وکیل

  14. Pingback: bi curious women

  15. Pingback: strap-on

  16. Pingback: mini wand massager

  17. Pingback: kvass

  18. Pingback: penile toy

  19. Pingback: Waterproof Vibrator

  20. Pingback: Karate master black trim gi

  21. Pingback: driving tips

  22. Pingback: bangal ka jadu

  23. Pingback: Mikemaid.com

  24. Pingback: مقالات دوربین مدار بسته

  25. Pingback: Anal toys

  26. Pingback: adam and eve

  27. Pingback: massage oil

  28. Pingback: Butt plugs

  29. Pingback: Dildo

  30. Pingback: billing

  31. Pingback: bunny rabbit

  32. Pingback: gay toys

  33. Pingback: adam and sextoy

  34. Pingback: Traditional cotton/poly taekwondo uniforms

  35. Pingback: porn watch

  36. Pingback: how cholesterol levels predict your health

  37. Pingback: php ecommerce

  38. Pingback: hipoteca

  39. Pingback: Safest forex brokers

  40. Pingback: intuit serial keys

  41. Pingback: Miami

  42. Pingback: Download Free TY Boogie Mixtapes

  43. Pingback: Out Of Town 66

  44. Pingback: Download Free DJ Finesse Mixtapes

  45. Pingback: port charges

  46. Pingback: ノロウイルス

  47. Pingback: inspekce jerabu

  48. Pingback: Bars Of Death,No DJ

  49. Pingback: pc games free download full version for windows 7

  50. Pingback: proforce lightweight blue martial arts gi

  51. Pingback: http://www.getappid.ir

  52. Pingback: emergency room glendale

  53. Pingback: best sex lube

  54. Pingback: prostate stimulation

  55. Pingback: ترمیم مو بیماران

  56. Pingback: bullet vibrator review

  57. Pingback: vibrator

  58. Pingback: adam and eve sex toys

  59. Pingback: bullet vibrator

  60. Pingback: 7 inch vibrator

  61. Pingback: پویاویلا

  62. Pingback: adam and eve sex toy shop

  63. Pingback: خريد اپل ايدي امريكا

  64. Pingback: اجاره ویلا چالوس

  65. Pingback: anal sex

  66. Pingback: big o multi stage vibrating penis ring

  67. Pingback: skin feel dildo

  68. Pingback: kala jadu

  69. Pingback: خرید اپل ایدی انلاین

  70. Pingback: magnetic label tape

  71. Pingback: temporary floor protection

  72. Pingback: تردمیل خانگی

  73. Pingback: polythene rolls

  74. Pingback: pallet wrap

  75. Pingback: wand vibrator

  76. Pingback: deepthroat

  77. Pingback: warning signs of infidelity

  78. Pingback: best ben wa balls

  79. Pingback: erotic

  80. Pingback: erotic

  81. Pingback: bondage gear

  82. Pingback: php web programming

  83. Pingback: خرید اپل ایدی

  84. Pingback: sex toys for gay

  85. Pingback: oral mints

  86. Pingback: vibrator

  87. Pingback: the bullet sex toy

  88. Pingback: small cap stocks

  89. Pingback: vpn خرید برای گوشی

  90. Pingback: Kids boxing bag starter kit

  91. Pingback: samuraiTV

  92. Pingback: lgbt sex toys

  93. Pingback: sex lubricants

  94. Pingback: sexy lingerie

  95. Pingback: ترمیم مو

  96. Pingback: طراحی سایت

  97. Pingback: Minihaziko

  98. Pingback: tratamento de Alcoolismo

  99. Pingback: home page

  100. Pingback: penis sleeve

  101. Pingback: adamandeve

  102. Pingback: Supply Chain

  103. Pingback: momentum stocks

  104. Pingback: Best Ben Wa Balls

  105. Pingback: Penis pump

  106. Pingback: Male Sex Toy

  107. Pingback: sex gel

  108. Pingback: lifelike vibrator

  109. Pingback: Female G Spot

  110. Pingback: adamandeve.com

  111. Pingback: icicles

  112. Pingback: magic wand vibrator

  113. Pingback: Sex toys in public prank

  114. Pingback: first anal vibrator

  115. Pingback: pc apps for windows 8

  116. Pingback: probiotic sauerkraut kvass

  117. Pingback: app for pc

  118. Pingback: free apps download for windows 10

  119. Pingback: free full download for windows

  120. Pingback: sex toys for beginners

  121. Pingback: sexy lingerie

  122. Pingback: rubber ducky vibrator

  123. Pingback: sex dildos

  124. Pingback: Erotic Toys for men

  125. Pingback: adam and eve

  126. Pingback: A\u0026E beginner's power pump

  127. Pingback: Price Comparison

  128. Pingback: pakistan lady burn out t shirts Factory

  129. Pingback: Vibrating Penis Ring

  130. Pingback: Penis Pump Review

  131. Pingback: best g-spot vibrator

  132. Pingback: Blowjob Sex Toy

  133. Pingback: RavingsbyRae

  134. Pingback: adam and eve sex toy

  135. Pingback: jbeatz

  136. Pingback: clit vibrator

  137. Pingback: massager

  138. Pingback: gay male toys

  139. Pingback: sex toys

  140. Pingback: Fuel injector

  141. Pingback: خرید دوربین مدار بسته

  142. Pingback: games for windows pc download

  143. Pingback: www.spu.ac.th

  144. Pingback: Bond cleaning services

  145. Pingback: sex lube

  146. Pingback: adult sex toy

  147. Pingback: adam and eve sex toys

  148. Pingback: Best Sex Lube

  149. Pingback: Bondage Restraint

  150. Pingback: Masturbator

  151. Pingback: Dolphin Vibrator

  152. Pingback: Clit Cream

  153. Pingback: Personal Massager

  154. Pingback: Butterfly Vibrator

  155. Pingback: Magic Massager

  156. Pingback: adam and eve sex toy

  157. Pingback: adam and eve vibrators

  158. Pingback: where to buy waterproof vibrator

  159. Pingback: interior design Singapore

  160. Pingback: kala jadu

  161. Pingback: Top Sports Stories and Sports Headlines

  162. Pingback: bandiera Italia

  163. Pingback: rental cleaning Melbourne

  164. Pingback: g-spot vibrator slim vibrator

  165. Pingback: rabbit vibe

  166. Pingback: Scented Candles,

  167. Pingback: dildo

  168. Pingback: anal toy

  169. Pingback: butt plug

  170. Pingback: first butt plug

  171. Pingback: sex toys for gay men

  172. Pingback: Central district seattl

  173. Pingback: Easy recipes for vegetarians

  174. Pingback: Bond back cleaning reviews

  175. Pingback: g spot stimulator

  176. Pingback: penis pumps

  177. Pingback: label besi

  178. Pingback: Weed Eater head

  179. Pingback: leather cleaning

  180. Pingback: real feel penis

  181. Pingback: adult games

  182. Pingback: free download for pc windows

  183. Pingback: being in the army

  184. Pingback: glass g spot vibrator

  185. Pingback: Taoist Real Sex Talk

  186. Pingback: I Love News Paper

  187. Pingback: a&e true feel

  188. Pingback: best butt plug

  189. Pingback: the sylvers

  190. Pingback: bangal ka jadu

  191. Pingback: most powerful vibrator

  192. Pingback: vibrator for beginners

  193. Pingback: Venture Point Network

  194. Pingback: website developers

  195. Pingback: rampant vibrator

  196. Pingback: CNC Machining Cover tube

  197. Pingback: high count sheets

  198. Pingback: silicone containers

  199. Pingback: online scr game

  200. Pingback: basement renovation in Atlanta

  201. Pingback: nippl sex toys

  202. Pingback: free download for windows pc

  203. Pingback: triple rabbit vibrator

  204. Pingback: realistic vibrating dildo

  205. Pingback: womens vibrator

  206. Pingback: realistic dong vibrator

  207. Pingback: vibrating dildo

  208. Pingback: free web hosting

  209. Pingback: Accessories

  210. Pingback: download tama tube

  211. Pingback: clínica de reabilitação

  212. Pingback: coffee’s best kona

  213. Pingback: RMUTT

  214. Pingback: coffee’s best kona

  215. Pingback: realistic dildo

  216. Pingback: ean codes

  217. Pingback: boogie board rental near me

  218. Pingback: sex toy bullet

  219. Pingback: ride sex toys

  220. Pingback: adam eve toys

  221. Pingback: sex toy review

  222. Pingback: sex toys cleaner

  223. Pingback: butterfly sex toys

  224. Pingback: cheap cock rings

  225. Pingback: g spot vibe

  226. Pingback: work at home jobs 2018

  227. Pingback: vintage collectibles

  228. Pingback: chinese antiquities

  229. Pingback: trička

  230. Pingback: sihir

  231. Pingback: lefkoşa kirakık ev fiyatları

  232. Pingback: murphy bed

  233. Pingback: robert

  234. Pingback: Internet Marketing

  235. Pingback: barcode kaufen

  236. Pingback: email database australia

  237. Pingback: Panoz

  238. Pingback: Pain Relief Oil

  239. Pingback: Double Sided Dildo

  240. Pingback: how to make money from home

  241. Pingback: adam and eve sex toy shop

  242. Pingback: everyday deals twitter

  243. Pingback: buy kona

  244. Pingback: kona 100%

  245. Pingback: email processing jobs

  246. Pingback: cock rings

  247. Pingback: Air Jordan 12 Low Cool Grey For Sale

  248. Pingback: women are aware

  249. Pingback: men

  250. Pingback: recovery clinic

  251. Pingback: web application development companies in usa

  252. Pingback: 50% of on Empty capsules!

  253. Pingback: gspot toy

  254. Pingback: Law enforcement black duty boots

  255. Pingback: Purchase Beer Online

  256. Pingback: Google

  257. Pingback: Google

  258. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.

  259. 第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。