GDUT_ winter training solution to a problem report _ the topic title I_F personal solution to a problem report

GDUT_ winter training solution to a problem report _ the topic title I_F personal solution to a problem report

topic:

Given a positive integer n, Write a program to find a non-zero multiple of the n-m, m shall mean that each one only contains 0 or 1 decimal. You can assume that n is not larger than 200 and not more than 100 m.
Tip: The title uses Special Judge, you do not need to output all eligible m, you only need to output either a qualified m can be.
Input
input comprising a plurality of sets of data, each data line only, contains only a positive integer n (. 1 <= n <= 200 is).
The Output
For each of the n-input, any one of output are qualified m. Even if there are multiple qualified m, you only need to output a can.
The Input the Sample
2
. 6
. 19
0
the Sample the Output
10
100100100100100100
111111111111111111

In fact, this problem is not so much data, each a minimum set of m is less than the long long, so the violence found in the past like the Orz, positive solution is dfs pruning

#define ULL unsigned long long
#define LL long long
using namespace std;
int t;
LL bfs(int k);
int main()
{
	while(~scanf("%d",&t)&&t)
	{
		printf("%lld\n",bfs(t));
	}

    return 0;
}
LL bfs(int k)
{
	queue<LL>que;

	que.push(1);
	while(!que.empty())
	{
		LL t=que.front();
		if(t%k==0)return t;
		que.pop();
		que.push(t*10+1);
		que.push(t*10);
	}
	return 1;
}
Released seven original articles · won praise 0 · Views 80

Guess you like

Origin blog.csdn.net/DevourPower/article/details/103963381