POJ 1426

一道联系参考价值不是很大的题

BFS,DFS搜索都是OK的,但是不要想着利用vis数组在进行什么优化了,因为这个Runtime Error了好几次,再去看discuss里的千奇百怪过样例(比如把输入原原本本回到输出就A了,可能和特判设置有关)

其实最建议的办法就是打表。

#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long LL;

const int maxb= 100;
const int maxn= 1<<15;

LL BFS(const int n)
{
	if (1== n){
		return 1;
	}
	queue<LL> Q;
	Q.push(1);

	while (!Q.empty()){
		LL x= Q.front();
		Q.pop();
		x*= 10;

		if (0== x%((LL)n)){
			return x;
		}
		Q.push(x);
		++x;
		if (0== x%((LL)n)){
			return x;
		}
		Q.push(x);
	} 

	return 0;
}

int main(int argc, char const *argv[])
{
	int n;
	while (~scanf("%d", &n) && n){
		printf("%lld\n", BFS(n));
	}
	return 0;
}
posted @   IdiotNe  阅读(36)  评论(0编辑  收藏  举报
编辑推荐:
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
阅读排行:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 用 C# 插值字符串处理器写一个 sscanf
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
点击右上角即可分享
微信分享提示