Give you a number N and find the smallest number that is a multiple of N. However, a number cannot be selected.
Solution:
BFS solves the problem by saving all the MOD files and not accessing the same MOD files that have already been accessed.
The new Mod = (mod * 10 + I) % N value is continuously added later.
Address: yet another multiple problem
# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; const int n = 10005; int A [10], n, m, FF, TT, Q [N], pre [N], Val [N]; void print (int x) {If (pre [x]) print (pre [x]); printf ("% d", Val [x]);} void solve () {FF = TT = 0; For (INT I = 1; I <10; I ++) if (I % N = 0 &&! A [I]) {printf ("% d \ n", I); return ;}// for (INT I = 1; I <10; I ++) if (! A [I] & Pre [I % N] =-1) {q [TT ++] = I % N; // mod pre [I % N] Saved by the root node = 0; // pre points to the front-end, and no front-end Val [I % N] = I; // save I, for output} while (FF <TT) {int u = Q [FF ++]; for (INT I = 0; I <10; I ++) if (! A [I]) {int v = (u * 10 + I) % N; If (V = 0) {print (U ); printf ("% d \ n", I); return;} If (pre [v] =-1) // It indicates that no v MOD has been accessed, then add it to the queue Q [TT ++] = V, pre [v] = u, Val [v] = I ;}} puts ("-1 ");} int main () {int CAS = 0, T; while (~ Scanf ("% d", & N) {memset (PRE,-1, sizeof (pre); memset (A, 0, sizeof ()); scanf ("% d", & M); For (INT I = 0; I <m; I ++) {scanf ("% d", & T ); A [T] = 1;} printf ("case % d:", ++ CAS); solve ();} return 0 ;}