POJ 1426 Find The Multiple(BFS)
程序员文章站
2022-06-12 09:01:13
...
题目链接:点击这里
题目给的样例太吓人了。
在czg大佬的指导下,long long水过。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
const int MOD = 10000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int maxn = 300;
int n;
bool BFS()
{
queue<ll> q;
q.push(1);
while(!q.empty())
{
ll top = q.front();
q.pop();
if(top%n==0)
{
printf("%lld\n", top);
return true;
}
q.push(top*10);
q.push(top*10+1);
}
return false;
}
int main()
{
while(~scanf("%d", &n)&&n)
BFS();
return 0;
}
推荐阅读
-
POJ 1465 Multiple G++ bfs 没掌握
-
POJ 1426 Find The Multiple 简单dfs构造
-
POJ-1426 Find The Multiple
-
POJ1426 Find The Multiple
-
POJ - 1426(Find The Multiple)
-
POJ1426 Find The Multiple(E)
-
POJ1426 Find The Multiple 题解
-
POJ 1426 Find The Multiple G++ dfs 巧妙
-
POJ 1426 Find The Multiple(BFS)
-
POJ 1426 Find The Multiple(BFS&&DFS)