zoukankan      html  css  js  c++  java
  • 【信息学奥赛一本通】第三部分_队列 ex2_3produce 产生数

      给出一个整数n(n<=2000)(代码可适用n<=10^31)和k个变换规则(k<=15)。

      规则:1、1个数字可以变换成另1个数字;

         2、规则中右边的数字不能为零。

      

      BFS

     1 #include <stdio.h>
     2 #include <string.h>
     3 #define maxn 1000
     4 
     5 char num[33];
     6 int len,q[maxn],Visited[11];
     7 long long ans = 1;
     8 
     9 int main (){
    10 //    freopen ("produce.in","r",stdin);
    11 //    freopen ("produce.out","w",stdout); 
    12     
    13     int i,j,k;
    14     int K,x[16],y[16];
    15     
    16     scanf ("%s%d",num,&K);
    17     for (i = 1;i<=K;i++)
    18         scanf ("%d%d",x+i,y+i);
    19     len = strlen (num);    
    20         
    21     int head = 0,tail = 0,temp;
    22         
    23     for (j = 0;j<len;j++){
    24         temp = 1;
    25         memset (Visited,0,sizeof(Visited));
    26         q[++tail] = num[j]-'0';
    27         do{
    28             head++;
    29             for (i = 1;i<=K;i++){
    30                 if (q[head] == x[i] && Visited[y[i]] == 0){
    31                     q[++tail] = y[i];
    32                     temp++;            
    33                     Visited[x[i]] = 1;
    34                     Visited[y[i]] = 1;
    35                 }
    36                 
    37             }
    38         }while (head<tail);
    39         ans*=temp;
    40     }
    41     
    42     printf ("%lld",ans);
    43     
    44     return 0;
    45 }
  • 相关阅读:
    webpack-bundle-analyzer使用
    HTTP1.0,HTTP1.1和HTTP2.0区别
    document.readyState
    async和defer
    页面生命周期
    key的理解
    解释型语言和编译型语言
    AMD/CMD/CommonJS与ES6 Module的区别
    vue的keep-alive原理
    数字钱包metaplex-foundation
  • 原文地址:https://www.cnblogs.com/Aeolus/p/5195931.html
Copyright © 2011-2022 走看看