zoukankan      html  css  js  c++  java
  • POJ 1426

    一道联系参考价值不是很大的题

    BFS,DFS搜索都是OK的,但是不要想着利用vis数组在进行什么优化了,因为这个Runtime Error了好几次,再去看discuss里的千奇百怪过样例(比如把输入原原本本回到输出就A了,可能和特判设置有关)

    其实最建议的办法就是打表。

    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <string>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <stack>
    #include <map>
    #include <set>
    using namespace std;
    
    typedef long long LL;
    
    const int maxb= 100;
    const int maxn= 1<<15;
    
    LL BFS(const int n)
    {
    	if (1== n){
    		return 1;
    	}
    	queue<LL> Q;
    	Q.push(1);
    
    	while (!Q.empty()){
    		LL x= Q.front();
    		Q.pop();
    		x*= 10;
    
    		if (0== x%((LL)n)){
    			return x;
    		}
    		Q.push(x);
    		++x;
    		if (0== x%((LL)n)){
    			return x;
    		}
    		Q.push(x);
    	} 
    
    	return 0;
    }
    
    int main(int argc, char const *argv[])
    {
    	int n;
    	while (~scanf("%d", &n) && n){
    		printf("%lld
    ", BFS(n));
    	}
    	return 0;
    }
    
  • 相关阅读:
    2016去哪儿编程题:乘坐公交
    lintcode:交错正负数
    lintcode:Ugly Number I
    KMP算法
    适配器模式
    迭代器模式
    命令模式
    外观模式
    工厂方法模式
    代理模式
  • 原文地址:https://www.cnblogs.com/Idi0t-N3/p/14687030.html
Copyright © 2011-2022 走看看