zoukankan      html  css  js  c++  java
  • HNUSTOJ-1565 Vampire Numbers(暴力打表)

    1565: Vampire Numbers

    时间限制: 3 Sec  内存限制: 128 MB
    提交: 20  解决: 9
    [提交][状态][讨论版]

    题目描述

    The number 1827 is an interesting number, because 1827=21*87, and all of the same digits appear on both sides of the `='. The number136948 has the same property: 136948=146*938.

    Such numbers are called Vampire Numbers. More precisely, a number v is a Vampire Number if it has a pair of factors, a and b, wherea*b = v, and together, a and b have exactly the same digits, in exactly the same quantities, as v. None of the numbers v, a or b can have leading zeros. The mathematical definition says that v should have an even number of digits and that a and b should have the same number of digits, but for the purposes of this problem, we'll relax that requirement, and allow a and b to have differing numbers of digits, and v to have any number of digits. Here are some more examples:

    126 = 6 * 21
    10251 = 51 * 201
    702189 = 9 * 78021
    29632 = 32 * 926
    

    Given a number X, find the smallest Vampire Number which is greater than or equal to X.

    输入

    There will be several test cases in the input. Each test case will consist of a single line containing a single integer X ( 10$ le$X$ le$1, 000, 000). The input will end with a line with a single `0'.

    输出

    For each test case, output a single integer on its own line, which is the smallest Vampire Number which is greater than or equal to X. Output no extra spaces, and do not separate answers with blank lines.

    样例输入

    10
    126
    127
    5000
    0

    样例输出

    126
    126
    153
    6880
    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<set>
     
    using namespace std;
    int vis[10];
    set<int> S;
    void Init_set(){
        for(int i = 1; i <= 1010; i++)
            for(int j = i; j <= 1000500/i; j++){
                int m = i * j;
                int tx = i, ty = j, tm = m;
                while(tm) {vis[ tm%10 ]++; tm /= 10;}
                while(tx) {vis[ tx%10 ]--; tx /= 10;}
                while(ty) {vis[ ty%10 ]--; ty /= 10;}
                bool is = true;
                for(int i = 0; i < 10; i++)
                    if(vis[i]) is = false, vis[i] = 0;
                if(is) S.insert( m );
            }
    }
    int main(){
        int x;
        Init_set();
        while(scanf("%d", &x) == 1 && x){
            printf("%d
    ", *S.lower_bound( x ));
        }
    }
     
  • 相关阅读:
    proc_create和create_proc_entry的区别
    ubuntn 12.04 rk环境及 相关使用 配置
    postcore_initcall(), arch_initcall(), subsys_initcall(), device_initcall() 调用顺序
    linux的zip 命令
    Mutex::AutoLock介绍
    camera 管脚功能和调试分析
    Android设备中实现Orientation Sensor(图)兼谈陀螺仪
    struct stat 操作 小结
    linux中字符串转换函数 simple_strtoul
    吴裕雄--天生自然轻量级JAVA EE企业应用开发Struts2Sping4Hibernate整合开发学习笔记:HibernateMap集合属性
  • 原文地址:https://www.cnblogs.com/Pretty9/p/7406651.html
Copyright © 2011-2022 走看看