Links: http://vjudge.net/problem/18284
Analysis: The problem of pancake-sharing. In order to make each number in the correct position from large to small, such as when dealing with the big I pancake, it will not affect the size of the 1,2,3,...,i-1 pancake (they have correctly turned to the bottom of the pancake heap i-1 position), the way to turn the pancake is to first turn to the top, and then turn to the right position, After the pancake piled bottom I position on the pancake has been properly put out of the tube, the next is to find the i+1 big pancake placed on the next number on the i+1 position, but for the current maximum pancake position to be classified discussion, if already in its correct position on nothing to do, if at the top, Just turn it over to the right position, or turn to the top and then turn to the right position.
1#include <string>2#include <iostream>3#include <sstream>4 using namespacestd;5 6 Const intMAXN = -+5;7 8 intN, A[MAXN];9 Ten voidFlipintp) { One for(inti =0; i < p-i; i++) ASwap (A[i], a[p-i]); -printf"%d"Np); - } the - intMain () { - strings; - while(Getline (CIN, s)) { +cout << S <<Endl; - StringStream SS (s); +n =0; A while(SS >> A[n]) n++; at for(inti = n-1; i >0; i--) { - intMAXV = a[i], index =i; - for(intj = i-1; J >=0; j--) - if(A[j] >MAXV) { -MAXV =A[j]; -index =J; in } - if(index = = i)Continue; to if(Index >0) Flip (index); + Flip (i); - } theprintf"0\n"); * } $ return 0;Panax Notoginseng}
UVa120 Stacks of Flapjacks (construction method)