zoukankan      html  css  js  c++  java
  • POJ 2275 Flipping Pancake

    点我看题目

    题意 : 按我自己的理解就是,给你n个数,按照从上到下排列,现在让你进行一系列的操作,让你将数按照从大到小排好。

    思路 : 比赛的时候以为要用记录路径的搜索,当时没什么把握,所以没做,今天网上一搜,我觉得这位神说的很对啊(链接),最简单的就是你从最大的开始换啊。

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <algorithm>
     5 
     6 using namespace std ;
     7 
     8 int a[35],b[35] ;
     9 
    10 int main()
    11 {
    12     int n ;
    13     int c[90] ;
    14     while(~scanf("%d",&n))
    15     {
    16         if(n == 0)
    17             break ;
    18         for(int i = 0 ; i < n ; i++)
    19         {
    20             scanf("%d",&a[i]) ;
    21             b[i] = a[i] ;
    22         }
    23         memset(c,0,sizeof(c)) ;
    24         int cnt = 0 ;
    25         sort(b,b+n) ;
    26        // reverse(b,b+n) ;
    27         for(int i = n-1 ; i > 0 ; i--)
    28         {
    29             if(a[i] != b[i])
    30             {
    31                 for(int j = 0 ; j < i ; j++)
    32                 {
    33                     if(b[i] == a[j])
    34                     {
    35                         if(j != 0)
    36                         {
    37                             c[cnt++] = j+1 ;
    38                             reverse(&a[0],&a[j+1]) ;
    39                         }
    40                         c[cnt++] = i+1 ;
    41                         reverse(&a[0],&a[i+1]) ;
    42                         break ;
    43                     }
    44                 }
    45             }
    46         }
    47         printf("%d ",cnt) ;
    48         for(int i = 0 ; i < cnt ; i ++)
    49             printf("%d ",c[i]) ;
    50         printf("
    ") ;
    51     }
    52     return 0 ;
    53 }
    View Code
  • 相关阅读:
    Kendo
    过河
    数组分组(简单dp)
    Codeforces Round #604 (Div. 2)(A-E)
    HDU1253
    HDU1026
    linux常用命令(二) --目录操作
    linux常用命令(一)--ls
    hdu 1072
    Codeforces Round #597 (Div. 2)(A-D)
  • 原文地址:https://www.cnblogs.com/luyingfeng/p/3661170.html
Copyright © 2011-2022 走看看