zoukankan      html  css  js  c++  java
  • ZOJ 3596 Digit Number(BFS)

    Digit Number

    Time Limit: 10 Seconds      Memory Limit: 65536 KB

    Given an integer n and an integer m, please calculate the minimal multiple of n which consists of exactly m different digits.

    Input

    This problem has several test cases. The first line of the input is an integer T (0 < T ≤ 150) indicates the number of test cases. Each test case is a line of 2 integers n (0 < n ≤ 1000) and m (0 < m ≤ 10)

    Output

    For each test case, if you can find the minimal multiple of n and x satisfying the above condition, please output a line as "x=n*y", otherwise output "Impossible" in a single line.

    Sample Input

    3
    37 1
    2 2
    100 1
    

    Sample Output

    111=37*3
    10=2*5
    Impossible
    

    Author: CAO, Peng
    Contest: The 12th Zhejiang University Programming Contest

    题意:求一个数N的最小的一个倍数中包含M个不同的数字。

    分析:这道题一开始真没想到会用BFS,我用的是最简单粗暴的枚举出倍数判断的方法,果断TLE。

    明显这道题如果用枚举倍数再判断的方法是不行的,因为并没有枚举的上界,倍数可以无限大,所以会超时。

    换个思路,采用BFS从高位试数字,用二进制或运算来记录哪一些数字是出现过的,还有到目前为止除以x后的余数,最大状态总数1024*1000,还要记录路径,因为要输出结果,目标状态是选取了恰好 m 个不同数字,且余数为 0 。路径可以直接用状态在队列里的下标来表示就可以,这种表示法的队列要求用数组,不能用STL。

  • 相关阅读:
    ubuntu golang nginx
    如何写易于调试的代码
    Topic 2: golang string operation
    topic 1: golang file operation
    【转帖】ArtisticStyle----很好用的C/C++样式格式化工具
    【转帖】C++经典书籍汇总
    (转载)MonoBehaviour的事件和具体功能总结
    unity3d的延时调用函数
    unity3D 实现手机的双指触控和Input类touch详解
    Lua 关于"."与":"号的用法区别
  • 原文地址:https://www.cnblogs.com/clliff/p/4483710.html
Copyright © 2011-2022 走看看