Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

此题有多组解,所以样例没过的同志,也要试试。

Posted by lzxzy at 2018-08-20 15:17:25 on Problem 1426
/*bfs*/
#include <cstdio>
#include <cstring>
using namespace std;
int n;
bool flag;

struct multi
{
	long long sum;
	int w;
}q[1000005];

void bfs()
{
	int l=1,r=1;
	struct multi tmp;
	q[1].sum=1;q[1].w=1;
	while(l<=r)
	{
		for(int i=0;i<=1;i++)
		{
			tmp=q[l];
			tmp.sum=tmp.sum*10+i;
			tmp.w++;
			if(tmp.sum%n==0)
			{
				printf("%I64d\n",tmp.sum);
				flag=true;
				return ;
			}
			r++;
			q[r]=tmp;
		}
		l++;
	}
}

int main()
{
	
	while(scanf("%d",&n) && n)
	{
		flag=false;
		bfs();
	}
	return 0;
}












/*dfs*/
#include <cstdio>
using namespace std;
int n;
bool flag;
long long ans;

void js(int w,long long sum)
{
	if(sum%n==0)
	{
		flag=true;
		ans=sum;
		return ;
	}
	if(w>18||flag)return ;
	for(int i=0;i<=1;i++)js(w+1,sum*10+i);
}

int main()
{
	while(scanf("%d",&n) && n)
	{
		ans=0;
		flag=false;
		js(1,1);
		printf("%I64d\n",ans);
	}
	return 0;
}


//代码奉上

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator