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 |
此题用queue广搜也行,只不过要用G++编译,用C++来编译就会TLE我的代码,里面也有深搜的代码 #include <iostream> #include<string> #include <fstream> #include <queue> using namespace std; //void DFS(long long k,int level); int n; long long result=0; bool flag; int main(int argc,char** argv) { // if(argc!=2)return 1; // ifstream infile(argv[1]); while(cin>>n,n) { //深搜代码 /*flag=false; DFS(1,1); if(flag) cout<<result<<endl;*/ //广搜代码 queue<long long > myQueue; myQueue.push(1); while(!myQueue.empty()) { long long front=myQueue.front(); myQueue.pop(); if(front%n!=0) { myQueue.push(front*10); myQueue.push(front*10+1); } else { cout<<front<<endl; break; } } } system("pause"); } /*void DFS(long long k,int level) { if(flag) return ; if(k%n==0) { result=k; flag=true; return ; } if(level==19) return ; DFS(k*10,level+1); DFS(k*10+1,level+1); }*/ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator