• 2012蓝桥杯专科组初赛第十题解答


      1 #include <stdio.h>
      2 char c[6];
      3 char ch[720][6];
      4 int ho;
      5 FILE * fp;
      6 void go_result(int * re);
      7 void go(int n);
      8 void swap(char * a, char * b);
      9 int main()
     10 {
     11     fp = fopen("result.txt", "w+");
     12     char zhong[7] = "ABCDE*";
     13     int i, j;
     14     ho = 0;
     15     for (i = 0; i < 6; i++)
     16         c[i] = zhong[i];
     17     go(0);
     18     int re1[720];
     19     ho = 0;
     20     for (i = 0; i < 720; i++)
     21         re1[i] = 0;
     22     for (i = 0; i < 6; i++)
     23         c[i] = zhong[i];
     24     go_result(re1);
     25     fclose(fp);
     26     printf("\nGame Over!");
     27     getch();
     28     return 0;
     29 }
     30 
     31 void go_result(int * re)
     32 {
     33     int i, j;
     34     for (i = 0; i < 720; i++) {
     35         for (j = 0; j < 6; j++)
     36             if (c[j] != ch[i][j])
     37                 break;
     38         if (j == 6) {
     39             if (re[i])
     40                 return;
     41             else {
     42                 ho++;
     43                 printf("%03d: ", ho);
     44                 fprintf(fp, "%03d: ", ho);
     45                 for (j = 0; j < 6; j++) {
     46                     if (j == 3) {
     47                         printf("\n     ");
     48                         fprintf(fp, "\n     ");
     49                     }
     50                     printf("%c ", c[j]);
     51                     fprintf(fp, "%c ", c[j]);
     52                 }
     53                 printf("\n\n");
     54                 fprintf(fp, "\n\n");
     55                 re[i] = 1;
     56             }
     57             break;
     58         }
     59     }
     60     for (i = 0; i < 6; i++)
     61         if (c[i] == '*')
     62             break;
     63     if (i == 0) {
     64         swap(c+0, c+1);
     65         go_result(re);
     66         swap(c+0, c+1);
     67         swap(c+0, c+3);
     68         go_result(re);
     69         swap(c+0, c+3);
     70     }
     71     if (i == 1) {
     72         swap(c+1, c+0);
     73         go_result(re);
     74         swap(c+1, c+0);
     75         swap(c+1, c+2);
     76         go_result(re);
     77         swap(c+1, c+2);
     78         swap(c+1, c+4);
     79         go_result(re);
     80         swap(c+1, c+4);
     81     }
     82     if (i == 2) {
     83         swap(c+2, c+1);
     84         go_result(re);
     85         swap(c+2, c+1);
     86         swap(c+2, c+5);
     87         go_result(re);
     88         swap(c+2, c+5);
     89     }
     90     if (i == 3) {
     91         swap(c+3, c+0);
     92         go_result(re);
     93         swap(c+3, c+0);
     94         swap(c+3, c+4);
     95         go_result(re);
     96         swap(c+3, c+4);
     97     }
     98     if (i == 4) {
     99         swap(c+4, c+3);
    100         go_result(re);
    101         swap(c+4, c+3);
    102         swap(c+4, c+1);
    103         go_result(re);
    104         swap(c+4, c+1);
    105         swap(c+4, c+5);
    106         go_result(re);
    107         swap(c+4, c+5);
    108     }
    109     if (i == 5) {
    110         swap(c+5, c+2);
    111         go_result(re);
    112         swap(c+5, c+2);
    113         swap(c+5, c+4);
    114         go_result(re);
    115         swap(c+5, c+4);
    116     }
    117 }
    118 
    119 void go(int n)
    120 {
    121     int i;
    122     for (i = 0; i < 6; i++)
    123         ch[ho][i] = c[i];
    124     ho++;
    125     int m;
    126     int k;
    127     n++;
    128     while(n < 6)
    129     {
    130         k = 0;
    131         m = 0;
    132         while (m < n)
    133         {
    134             swap(c-n+5, c-k+5);
    135             go(n);
    136             swap(c-n+5, c-k+5);
    137             k++;
    138             m++;
    139         }
    140         n++;
    141     }
    142 }
    143 
    144 void swap(char * a, char * b)
    145 {
    146     char i = *a;
    147     *a = *b;
    148     *b = i;
    149 }

    devcpp测试通过,不是答题,只是思路

    几许风雨天,千里孤月夜。日出似无时,何处现流光。
  • 相关阅读:
    和Java相关的书籍,想成为架构师的请收藏一下啊
    CF1404C Fixed Point Removal 题解
    Harbour.Space Scholarship Contest 2021-2022 (open for everyone, rated, Div. 1 + Div. 2) E~G 题解
    ABC223G Vertex Deletion 题解
    ARC103D Distance Sums 题解
    ARC103B Robot Arms 题解
    ABC221G Jumping sequence 题解
    ABC221F Diameter set 题解
    ABC211H Count Multiset 题解
    CF1342E Placing Rooks 题解
  • 原文地址:https://www.cnblogs.com/shendiao/p/2486856.html
Copyright © 2020-2023  润新知