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 ;}