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:史上最短的搜索代码!bfs和dfs都很简单!In Reply To:史上最短的搜索代码!bfs和dfs都很简单! Posted by:chenxuan123456789 at 2012-11-04 11:36:43 > #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