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

先贴一个bfs,再看看dfs

Posted by TSERROF at 2012-10-19 11:01:38 on Problem 1426
#include<iostream>
#include <queue>
using namespace std;
int n;
long long BFS()
{
	queue<long long>ans;
	while(!ans.empty())ans.pop();
	ans.push(1);
	while(!ans.empty())
	{
		if(ans.front()%n==0)return ans.front();
		long long temp=ans.front();
		ans.pop();
		ans.push(temp*10);
		ans.push(temp*10+1);
	}
	return 0;
}
int main()
{
	while(cin>>n && n)cout<<BFS()<<endl;
	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