| ||||||||||
| 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 | |||||||||
史上最短的搜索代码!bfs和dfs都很简单!#include <iostream>
#include <queue>
using namespace std;
int n;
long long bfs()
{
queue<long long> p;
while(!p.empty())
p.pop();
p.push(1);
while(1)
{
long long sum=p.front();
if(sum%n==0)
return sum;
p.pop();
p.push(10*sum);
p.push(10*sum+1);
}
}
int main()
{
while(cin>>n,n)
{
cout<<bfs()<<endl;
}
return 1;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator