zoukankan      html  css  js  c++  java
  • 移动字母

     1 #include<stdio.h>
     2 #include<string.h>
     3 
     4 char a[7];
     5 char b[750][7];
     6 char c[6]={'A','B','C','D','E','*'};
     7 int t[4][2]={1,0,0,1,0,-1,-1,0};
     8 int temp;
     9 
    10 int fun(char *p,int n,int m)
    11 {
    12     int i,j,x,y,u;
    13     char v[6],k;
    14     if(!(strcmp(p,c))) return 1;
    15     else
    16         for(i=0;i<4;i++)
    17         {
    18             x=n+t[i][0];
    19             y=m+t[i][1];
    20             strcpy(v,p);
    21             if(x>=0&&x<2&&y>=0&&y<3)
    22             {
    23                 k=v[x*3+y];
    24                 v[x*3+y]=v[n*3+m];
    25                 v[n*3+m]=k;
    26                 u=1;
    27                 for(j=0;j<temp;j++)
    28                     if(!strcmp(v,b[j]))
    29                     {
    30                         u=0; 
    31                         break;
    32                     }
    33 
    34                     if(u)
    35                     {
    36                         strcpy(b[temp++],v);
    37                         return fun(v,x,y);
    38                     }
    39             }
    40         }
    41         return 0;
    42 }
    43 
    44 int main()
    45 {
    46     int i,n,m,k;
    47     scanf("%d",&k);
    48     while(k--)
    49     {
    50         temp=1;
    51         scanf("%s",a);
    52         strcpy(b[0],a);
    53         for(i=0;i<6;i++)
    54             if(a[i]=='*') break;
    55             n=i/3;
    56             m=i%3;
    57         printf("%d\n",fun(a,n,m));
    58     }
    59     return 0;
    60 }
  • 相关阅读:
    确定查询各阶段消耗的时间
    mysql 处理查询请求过程
    如何获取有性能问题的SQL
    索引优化策略
    CXF支持 SOAP1.1 SOAP1.2协议
    MYSQL 基于GTID的复制
    poj2056
    poj2049
    poj1033
    poj1221
  • 原文地址:https://www.cnblogs.com/xiaofanke/p/3035415.html
Copyright © 2011-2022 走看看