没有输出,9999
查看原帖
没有输出,9999
762199
fulichang楼主2023/8/14 11:02
#include <iostream>
#include <queue>

using std::string;

int a, len;
int ans[1000];
bool vis[100005];

int hp (string b) {
	int p = 0;
	for (int i = 0; i < len; i++) {
		p = p * 10 + (b[i] - '0');
		ans[i] = p / a;
		p %= a;
		std::cout << p << ' ' << b << std::endl;
	}
	return p;
}

void bfs () {
	std::queue <string> q;
	q.push("1");
	while (!q.empty()) {
		string tmp = q.front();
		q.pop();
		len = tmp.size();
		int p = hp(tmp);
		vis[p] = true;
		if (!p) {
			bool flag = false;
			for (int i = 0; i < len; i++) {
				if (!flag && !ans[i] && i != len - 1)
					continue;
				else
					flag = true;
				printf ("%d", ans[i]);
			}
			std::cout << ' ' << tmp << std::endl;
			return;
		}
		std::cout << hp(tmp + '0') << ' ' << hp(tmp + '1') << std::endl;
		if (!vis[hp(tmp + '0')])
			q.push(tmp + '0');
		if (!vis[hp(tmp + '1')])
			q.push(tmp + '1');
	}
}

int main() {
	scanf ("%d", &a);
	bfs();
	return 0;
}
2023/8/14 11:02
加载中...