description:http://acm.swust.edu.cn/problem/0254/
Problem-solving ideas: First find the largest pancake, first flipped to the top, and finally flipped to the bottom
AC Code:
#include <stdio.h>intTime=0;intdigit[ +];voidTurnintAintb//Flipping Pancakes{ inti=a,j=b; while(i<j) { intt=Digit[i]; Digit[i]=Digit[j]; DIGIT[J]=T; I++; J--; } Time++;//Times plus One}intFindmax (intAintb//find the maximum element's foot tag{ intMax,i; Max=A; for(i=a+1; i<=b;i++) if(digit[i]>Digit[max]) Max=i; returnMax;}voidChangeintY//find the largest number first, flip to the top, flip to the bottom{ if(y==0) return; intMaxn=findmax (0, y); if(maxn!=0&&maxn!=y) {Turn (0, MAXN); Turn (0, y); } Else if(maxn==0) Turn (0, y); Change (y-1);}intMain () {intN; scanf ("%d",&N); inti; for(i=0; i<n;i++) scanf ("%d",&Digit[i]); Change (N-1); printf ("%d\n", time);//For (i=0;i<n;i++)//printf ("%d", Digit[i]); return 0;}
Stir-fried pancake (swust OJ 0254)