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 zsc09_leaf at 2011-04-07 19:13:56 on Problem 1426
//192K,16MS
#include <iostream>
#include <queue>
#include <string>
#include <CSTDIO>
using namespace std;
string ans[210];
bool mark[210];
struct node
{
	string ans;
	int mod;
};
string BFS(int n)
{
	memset(mark,0,sizeof(mark));
	queue<node>q;
	node s;
	s.ans="1"; 
	s.mod=1;
	q.push(s);
	mark[1]=true;
	while(!q.empty())
	{
		node now=q.front(),temp=now;
		q.pop();
		int c=(now.mod*10+1)%n;
		int d=(now.mod*10)%n;
		if(d==0)
		{
			temp.ans+="0";
			return temp.ans;
		}
		 if(c==0)
		{
			temp.ans+="1";
			return temp.ans;
		}
		 if(!mark[d])
		{
			mark[d]=1;
			temp.ans+="0";
			temp.mod=d;
			q.push(temp);
		}
		 if(!mark[c])
		{
			mark[c]=1;
			now.ans+="1";
			now.mod=c;
			q.push(now);
		}
	}
}
int main()
{
	int n;
	for(int i=1;i<=200;i++)
	{
		if(i&1)
			ans[i]=BFS(i);
		else
			ans[i]=ans[(i>>1)]+"0";
	}
	while (scanf("%d",&n)&&n)
	{
		cout<<ans[n]<<endl;
	}
}

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