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 va 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 ( 10X1, 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[];
set<int> S;
void Init_set(){
for(int i = ; i <= ; i++)
for(int j = i; j <= /i; j++){
int m = i * j;
int tx = i, ty = j, tm = m;
while(tm) {vis[ tm% ]++; tm /= ;}
while(tx) {vis[ tx% ]--; tx /= ;}
while(ty) {vis[ ty% ]--; ty /= ;}
bool is = true;
for(int i = ; i < ; i++)
if(vis[i]) is = false, vis[i] = ;
if(is) S.insert( m );
}
}
int main(){
int x;
Init_set();
while(scanf("%d", &x) == && x){
printf("%d\n", *S.lower_bound( x ));
}
}
 

HNUSTOJ-1565 Vampire Numbers(暴力打表)的更多相关文章

  1. codeforces 9 div2 C.Hexadecimal's Numbers 暴力打表

    C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input stand ...

  2. XTU OJ 1210 Happy Number (暴力+打表)

    Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...

  3. The 70th problem,UVa10396 Vampire Numbers

    今天看Thinking in Java看到一个吸血鬼数的问题,于是查找UVa里也有类似的问题就动手写了先是用Java写的,不过WA了两次,然后没有发现错误,又用c++写的还是不行.最后发现要排序去重. ...

  4. HDU 1216 Assistance Required(暴力打表)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1216 Assistance Required Time Limit: 2000/1000 MS (Ja ...

  5. ACM/ICPC 之 暴力打表(求解欧拉回路)-编码(POJ1780)

    ///找到一个数字序列包含所有n位数(连续)一次且仅一次 ///暴力打表 ///Time:141Ms Memory:2260K #include<iostream> #include< ...

  6. 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

  7. HDU 1012 u Calculate e【暴力打表,水】

    u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. Codeforces 914 C 数位DP+暴力打表+思维

    题意 给出一个二进制数\(n\),每次操作可以将一个整数\(x\)简化为\(x\)的二进制表示中\(1\)的个数,如果一个数简化为\(1\)所需的最小次数为\(k\),将这个数叫做特殊的数, 问从\( ...

  9. Friends number NBUT - 1223 (暴力打表)

    Paula and Tai are couple. There are many stories between them. The day Paula left by airplane, Tai s ...

随机推荐

  1. wed.xml 中 filter、servlet 配置格式

    1.wed.xml 中 filter 配置格式 <filter> <filter-name>filterName</filter-name> <filter- ...

  2. ThoughtWorks.QRCode 生成二维码名片(实现二维码内容换行)

    最近在写一个很简单的功能,按照Vcard的格式,生成二维码名片.本来以为分分钟完事的事情,替换数据,直接调用dll去生成二维码. 测试时,发现生成的二维码使用微信扫描得到的名片信息为空,反向解析发现, ...

  3. PHP 字符串相关常识

    0x00 前言 第一次遇见字符串这个概念是在学 C 语言的时候,那时候觉得字符串也没有什么难的,不就是一个以 \0 结尾的 char 数组而已咯.后来在学习 PHP 的过程中也同样保持这个观念,不过在 ...

  4. Selenium 警告框处理

    警告框分三种类型: alert:显示带有一条指定消息和一个 OK 按钮的警告框. confirm:显示一个带有指定消息和 OK 及取消按钮的对话框. prompt:显示可提示用户进行输入的对话框. 我 ...

  5. Spring Boot教程(十五)使用Intellij中的Spring Initializr来快速构建Spring Boot/Cloud工程

    在之前的所有Spring Boot和Spring Cloud相关博文中,都会涉及Spring Boot工程的创建.而创建的方式多种多样,我们可以通过Maven来手工构建或是通过脚手架等方式快速搭建,也 ...

  6. android存储路径问题

    关于存储路径问题,如果是想要存储在应用本身的路径下,如果该应用卸载的时候,对应文件随之卸载, 如果使用的是android level 8以上的版本,采用的是: getExternalFilesDir( ...

  7. 大数据笔记(三十二)——SparkStreaming集成Kafka与Flume

    三.集成:数据源 1.Apache Kafka:一种高吞吐量的分布式发布订阅消息系统 (1) (*)消息的类型 Topic:主题(相当于:广播) Queue:队列(相当于:点对点) (*)常见的消息系 ...

  8. 《Effective Java》读书笔记 - 7.方法

    Chapter 7 Methods Item 38: Check parameters for validity 直接举例吧: /** * ...其他的被我省略了 * @throws Arithmet ...

  9. win10 配置tensorflow环境

    1. 在anaconda中新增环境 python3.5, 我使用的是anaconda-navigator 中新增的环境,python版本选择3.5 2. 激活新增加的环境, 注意win下,没有sour ...

  10. The file is inaccessible to Server.

    ArcGIS Unable to Start serviceserver安装后,启动服务失败,报错信息如下:Unable to Start service. Error (Server object  ...