(White Book Training Program) ultraviolet A 120 stacks of flapjacks (constructor)

Source: Internet
Author: User

Subject address: Ultraviolet A 120

Question. Shift from the largest start, and each time the big one is first moved to the top and then to the bottom.

The Code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int a[500], b[500], d[500];int main(){    int i, j, flag, cnt, n, x, m;    while(scanf("%d",&a[0])!=EOF)    {        b[a[0]]=0;        d[0]=a[0];        i=1;        cnt=0;        while(getchar()!='\n')        {            scanf("%d",&a[i]);            d[i]=a[i];            b[a[i]]=i;            i++;        }        n=i;        m=n;        for(i=0; i<n; i++)        {            printf("%d",a[i]);            if(i!=n-1)                printf(" ");        }        printf("\n");        sort(d,d+n);        while(n--)        {            if(b[d[n]]==n)                continue ;            if(b[d[n]]!=0)            {                x=b[d[n]];                printf("%d ",m-x);                for(i=0; i<=x; i++)                {                    b[a[i]]=x-b[a[i]];                }                for(i=0; i<=x/2; i++)                {                    int t=a[i];                    a[i]=a[x-i];                    a[x-i]=t;                }            }            for(i=0; i<=n; i++)            {                b[a[i]]=n-b[a[i]];            }            for(i=0; i<=n/2; i++)            {                int t=a[i];                a[i]=a[n-i];                a[n-i]=t;            }            printf("%d ",m-n);        }        printf("0\n");    }    return 0;}


(White Book Training Program) ultraviolet A 120 stacks of flapjacks (constructor)

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.