| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:改进了一点点,变成32ms 740kb了,虽然也不快In Reply To:先贴一个bfs,再看看dfs Posted by:TSERROF at 2012-10-19 11:01:38 #include<iostream>
#include <cstring>
#include <queue>
using namespace std;
int n;
bool repeat[201];
long long BFS()
{
queue<long long>ans;
ans.push(1);
while(!ans.empty())
{
if(ans.front()%n==0)return ans.front();
repeat[ans.front()%n]=true;
if(!repeat[(ans.front()*10)%n])ans.push(ans.front()*10);
if(!repeat[(ans.front()*10+1)%n])ans.push(ans.front()*10+1);
ans.pop();
}
return 0;
}
int main()
{
while(cin>>n && n)cout<<BFS()<<endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator