您的位置:首页 > 其它

POJ1426——DFS——Find The Multiple

2015-08-09 16:07 435 查看
http://poj.org/problem?id=1426

/*
暴力发现最大数目不超过19位,开unsigned long long 水过
*/
/************************************************
* Author        :Powatr
* Created Time  :2015-8-9 15:30:37
* File Name     :E.cpp
************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int n;
queue <unsigned long long > q;
unsigned long long  bfs(){
while(!q.empty()) q.pop();
q.push(1);
while(!q.empty()){
unsigned long long x = q.front();
q.pop();
if(x % n == 0)  return x;
q.push(x*10);
q.push(x*10 + 1);
}
}
int main(){
while(~scanf("%d", &n) && n){
printf("%llu\n", bfs());
}
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: