zoukankan      html  css  js  c++  java
  • nyoj-93-汉诺塔(三)

    这是误打误撞弄出来的  相反思路   呵呵 贴上来给思路

     1  
     2 #include<stdio.h>
     3 #include<string.h>
     4 #include<algorithm>
     5 #include<math.h>
     6 using namespace std;
     7 struct zhan
     8 {
     9     int z[65],top;
    10 }z[3];
    11 int main()
    12 {
    13     bool move(int m,int n);
    14     int n,p,q,a,b,i;
    15     scanf("%d",&n);
    16     while(n--)
    17     {
    18         scanf("%d%d",&p,&q);
    19         for(i=0;i<=p;i++)
    20         z[0].z[i]=i;
    21         z[0].top=p;z[1].top=z[2].top=0;
    22         int flag=1;
    23         for(i=0;i<q;i++)
    24         {
    25             scanf("%d%d",&a,&b);
    26             if(flag)
    27             {
    28                 if(move(a-1,b-1)==0)
    29                 flag=0;
    30             }
    31         }
    32         printf(flag?"legal
    ":"illegal
    ");
    33     }
    34     return 0;
    35 }
    36 
    37 bool move(int m,int n)
    38 {
    39     //printf("%d %d %d %d %d %d
    ",m,n,z[m].top,z[n].top,z[m].z[z[m].top],z[n].z[z[n].top]);
    40     if(z[m].top!=0&&z[m].z[z[m].top]>z[n].z[z[n].top])
    41     {
    42         z[n].z[++z[n].top]=z[m].z[z[m].top--];
    43         return 1;
    44     }
    45     else
    46     return 0;
    47 }
    48         

    这是改过之后的模拟思路

     1  
     2 #include<stdio.h>
     3 #include<string.h>
     4 #include<algorithm>
     5 #include<math.h>
     6 using namespace std;
     7 struct zhan
     8 {
     9     int z[65],top;
    10 }z[3];
    11 int main()
    12 {
    13     bool move(int m,int n);
    14     int n,p,q,a,b,i;
    15     scanf("%d",&n);
    16     while(n--)
    17     {
    18         scanf("%d%d",&p,&q);
    19         for(i=0;i<=p;i++)
    20         z[0].z[i]=p-i+1;
    21         z[0].top=p;z[1].top=z[2].top=0;
    22         int flag=1;
    23         for(i=0;i<q;i++)
    24         {
    25             scanf("%d%d",&a,&b);
    26             if(flag)
    27             {
    28                 if(move(a-1,b-1)==0)
    29                 flag=0;
    30             }
    31         }
    32         printf(flag?"legal
    ":"illegal
    ");
    33     }
    34     return 0;
    35 }
    36 
    37 bool move(int m,int n)
    38 {
    39     //printf("%d %d %d %d %d %d
    ",m,n,z[m].top,z[n].top,z[m].z[z[m].top],z[n].z[z[n].top]);
    40     if(z[m].top==0||z[n].top!=0&&z[m].z[z[m].top]>z[n].z[z[n].top])
    41     return 0;
    42     else
    43     {
    44         z[n].z[++z[n].top]=z[m].z[z[m].top--];
    45         return 1;
    46     }
    47 }
    48         
  • 相关阅读:
    .NET Core自定义TagHelper和使用Serilog
    .NET Core CSRF
    jq 获取表单全部数据
    Webuploader 简单图片上传 支持多图上传
    CF-1451 E Bitwise Queries 异或 交互题
    CF-1440C2 Binary Table (Hard Version) (构造,模拟)
    CF-1445 C
    ACM模板_axiomofchoice_extra
    Codeforces Round #678 (Div. 2) 题解 (A-E)
    Oracle数据同步
  • 原文地址:https://www.cnblogs.com/nylg-haozi/p/3198525.html
Copyright © 2011-2022 走看看