HDU 3328 Flipper (stack)

Source: Internet
Author: User

Recently, I started to lay the foundation for doing STL questions. Although it is not difficult for STL questions, however, we need to speed up the accuracy ............................. there are N cards in this question, one at each position at the beginning (face up or down), there is a N-1 operation, each operation from the leftmost or rightmost of the card, turn the cards in the heap from top to bottom to the heap next to it. The operation is over, with only one heap left. Execute Q queries in the pile, from top to bottom, number of the initial card status and whether it is facing up or down. Directly enable N stacks to store the status of all the stacks... simulate the operation.

# Include <iostream> # include <algorithm> # include <cmath> # include <functional> # include <cstdio> # include <cstdlib> # include <cstring> # include <string> # include <vector> # include <set> # include <queue> # include <stack> # include <climits> // # define MAX 100005 # define INF 0x7FFFFFFF using namespace std; int s [111] [111]; int head [111]; int n, q; int numl, numr, final; char sta [111]; char op [111]; void init () {memset (s, 0, sizeof (s); memset (head, 0, sizeof (head); numl = 0; numr = 0 ;} void solve () {for (int I = 1; I <= n; I ++) {s [I] [0] = I ;} int len = strlen (op); int right, left; for (int I = 0; I <len; I ++) {if (op [I] = 'R') {numr ++; left = n-numr; right = left + 1; while (head [right]>-1) {s [left] [++ head [left] = s [right] [head [right] --] ;}} else {numl ++; left = numl; right = left + 1; while (head [left]>-1) {s [right] [++ head [right] = s [left] [head [left] --] ;}}} bool judge (int x, int y) {int span = abs (x-y); if (span % 2 = 1) {if (sta [Y-1] = 'U ') sta [Y-1] = 'D'; else sta [Y-1] = 'U';} if (sta [Y-1] = 'U') return 1; return 0 ;} int main () {int a; int ca = 1; while (scanf ("% d", & n) {init (); scanf ("% s", sta); scanf ("% s", op); scanf ("% d", & q); solve (); final = 1 + numl; printf ("Pile % d \ n", ca ++); for (int I = 0; I <q; I ++) {scanf ("% d", & a); printf ("Card % d is a", a); if (judge (final, s [final] [n-a]) = 0) printf ("face down % d. \ n ", s [final] [n-a]); else printf (" face up % d. \ n ", s [final] [n-a]) ;}} return 0 ;}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.