zoukankan      html  css  js  c++  java
  • ZOJ 1136 Mutiple (同余定理判重)

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <algorithm>
     5 #include <queue>
     6 #define sc(x) scanf("%d",&x)
     7 #define pf(x) printf("%d
    ",x)
     8 #define P printf("
    ")
     9 #define CL(x,y) memset(x, y, sizeof(x))
    10 #define FOR(i,x,v) for(int i=x; i<=v; i++)
    11 using namespace std;
    12 struct node
    13 {
    14     int num;
    15     string str;
    16 };
    17 const int MAX = 5002;
    18 int N, M, arr[10], used[MAX], i, temp;
    19 queue <node> Q;
    20 void BFS();
    21 int main()
    22 {
    23     int i;
    24     while(sc(N)!=EOF)
    25     {
    26         sc(M);
    27         FOR(i, 0, M-1)
    28         sc(arr[i]);
    29         sort(arr, arr+M);
    30         CL(used, 0);
    31         while(!Q.empty ())
    32             Q.pop ();
    33         if(N==0) pf(0);
    34         else
    35             BFS();
    36         while(!Q.empty())
    37             Q.pop ();
    38 //        P;
    39     }
    40     return 0;
    41 }
    42 void BFS()
    43 {
    44     node fir, cur, next;
    45     fir.num = 0;
    46     fir.str = "";
    47     Q.push(fir);
    48     while(!Q.empty())
    49     {
    50         cur = Q.front();
    51         Q.pop();
    52 //        if(cur.num >= N && cur.num % N == 0)
    53 //        {
    54 //            pf(cur.num);
    55 //            return ;
    56 //        }
    57         FOR(i, 0, M-1)
    58         {
    59             temp = cur.num*10 + arr[i];
    60             if(!temp) continue;
    61             if(temp%N==0)
    62             {
    63                 cout << cur.str << (char)(arr[i]+'0') << endl;
    64                 return ;
    65             }
    66             if(!used[temp%N])
    67             {
    68                 used[temp%N] = 1;
    69                 next.num = temp%N;
    70                 next.str = cur.str + (char)(arr[i]+'0');
    71                 Q.push(next);
    72             }
    73         }
    74     }
    75     pf(0);
    76 }
    View Code

    虽然错了10次,还是不清楚到底怎么了。。。等几天才懂了那个string 的含义

  • 相关阅读:
    RatProxy
    Jacob
    系统二级运维之业务单据错误处理
    材料的构成 —— 塑料
    作文 —— 诙谐、幽默、调侃、批判
    作文 —— 诙谐、幽默、调侃、批判
    (中英)作文 —— 标题与小标题
    公司的组成
    公司的组成
    数据结构的时间复杂度与空间复杂度、及相关证明
  • 原文地址:https://www.cnblogs.com/ghostTao/p/4336004.html
Copyright © 2011-2022 走看看