Find The Multiple POJ - 1426
题目链接:https://cn.vjudge.net/problem/POJ-1426
注意:队列在每次使用的时候都需要清空 否则内存会超限
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <queue> 5 #include <algorithm> 6 #define mem(a,b) memset(a,b,sizeof(a)); 7 using namespace std; 8 #define INF 0x3f3f3f3f 9 typedef long long ll; 10 int dir[4][2] = {0,1,0,-1,1,0,-1,0}; 11 const int maxn = 100005; 12 ll n,ans; 13 int flag; 14 queue<ll>q; 15 void bfs(ll m) { 16 q.push(m); 17 while(!q.empty()){ 18 ll k = q.front(); 19 q.pop(); 20 if(k % n == 0){ 21 cout << k << endl; 22 break; 23 } 24 q.push(k*10); 25 q.push(k*10+1); 26 } 27 } 28 int main() 29 { 30 while(cin >> n&&n) { 31 while(!q.empty()) 32 q.pop(); 33 flag = 0; 34 bfs(1); 35 } 36 return 0; 37 }