zoukankan      html  css  js  c++  java
  • 01的时间

    1.做BFS时要记录路径。

    2.注意模的性质~~~大佬给我说的

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<queue>
     6 using namespace std;
     7 
     8 const int maxn=1000;
     9 
    10 int p[maxn],pre[maxn];
    11 
    12 void print(int m){
    13     if(m==-1) return;
    14     print(pre[m]);
    15     printf("%d",p[m]);
    16 }
    17 
    18 void BFS(int n){
    19     queue<int> q;
    20     q.push(1);
    21     p[1]=1,pre[1]=-1;
    22     while(q.size()){
    23         int v=q.front();
    24         q.pop();
    25         int x=(v*10)%n;
    26         int y=(v*10+1)%n;
    27         if(x==0){
    28             print(v);
    29             cout<<"0"<<endl;
    30             break;
    31         }
    32         if(y==0){
    33             print(v);
    34             cout<<"1"<<endl;
    35             break;
    36         }
    37         if(pre[x]==0){
    38             pre[x]=v;
    39             p[x]=0;
    40             q.push(x);
    41         }
    42         if(pre[y]==0){
    43             pre[y]=v;
    44             p[y]=1;
    45             q.push(y);
    46         }
    47     }
    48 }
    49 
    50 int main()
    51 {   int T;scanf("%d",&T);
    52     while(T--){
    53         int tem;scanf("%d",&tem);
    54         memset(p,0,sizeof(p));
    55         memset(pre,0,sizeof(pre));
    56         if(tem==1) printf("1
    ");
    57         else BFS(tem);
    58         
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    _status()函数
    _clear87()函数
    _clear87()函数
    _clear87()函数
    _clear87()函数
    南邮NOJ1009 2的n次方
    南邮NOJ2063 突发奇想的茂凯
    南邮NOJ2063 突发奇想的茂凯
    【HDOJ】1297 Children’s Queue
    【HDOJ】2103 Family planning
  • 原文地址:https://www.cnblogs.com/zgglj-com/p/6864363.html
Copyright © 2011-2022 走看看