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
X
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[];
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(暴力打表)的更多相关文章
- 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 ...
- XTU OJ 1210 Happy Number (暴力+打表)
Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...
- The 70th problem,UVa10396 Vampire Numbers
今天看Thinking in Java看到一个吸血鬼数的问题,于是查找UVa里也有类似的问题就动手写了先是用Java写的,不过WA了两次,然后没有发现错误,又用c++写的还是不行.最后发现要排序去重. ...
- HDU 1216 Assistance Required(暴力打表)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1216 Assistance Required Time Limit: 2000/1000 MS (Ja ...
- ACM/ICPC 之 暴力打表(求解欧拉回路)-编码(POJ1780)
///找到一个数字序列包含所有n位数(连续)一次且仅一次 ///暴力打表 ///Time:141Ms Memory:2260K #include<iostream> #include< ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- HDU 1012 u Calculate e【暴力打表,水】
u Calculate e Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- Codeforces 914 C 数位DP+暴力打表+思维
题意 给出一个二进制数\(n\),每次操作可以将一个整数\(x\)简化为\(x\)的二进制表示中\(1\)的个数,如果一个数简化为\(1\)所需的最小次数为\(k\),将这个数叫做特殊的数, 问从\( ...
- Friends number NBUT - 1223 (暴力打表)
Paula and Tai are couple. There are many stories between them. The day Paula left by airplane, Tai s ...
随机推荐
- PHP基础-表达式介绍
表达式是 PHP 最重要的基石.在PHP 编程 中,几乎所写的任何东西都是一个表达式.简单但却最精确的定义一个表达式的方式就是“任何有值的东西”. 最基本的表达式形式是常量和变量.当键入“$a = 5 ...
- React Native中集成友盟社会化分享-----童叟无欺
1.下载所需的jar,下载地址https://developer.umeng.com/sdk/reactnative?spm=a211g2.211692.0.0.28967d238GW6mC 2.将以 ...
- Halcon链接库
halcon.libhalconc.libhalconcpp.libhalconcppxl.libhalconcxl.libhalconx.libhalconxl.libhalconxxl.libhd ...
- 【python学习之五】自定义函数实现用 Python 发送电子邮件
前言 之前论坛里有人发过关于发送邮件的帖子,设计器也有关于发送邮件的控件.我这里再次重复,希望能有帮到大家的地方. 信息准备 发送邮件前必须准备好一些基本信息,例如发件人邮箱地址.发件人邮箱密码.收件 ...
- A - 地震预测
A - 地震预测 怀特先生是一名研究地震的科学家,最近他发现如果知道某一段时间内的地壳震动能量采样的最小波动值之和,可以有效地预测大地震的发生. 假设已知一段时间的n次地壳震动能量的采样值为a1,a2 ...
- oracle调整链接数
50用户以下:8GB 混用,oracle 占据1GB~3GB内存,open_cursors:300,processes:10050-100用户:16GB 混用,oracle 占据3~4GB内存,ope ...
- 使用 java替换web项目的web.xml
创建一个接口: package my.web; public interface SpringWeb { void config(); } 实现类: package my; import my.web ...
- 记一次全局分区索引update调优
原始SQL: CREATE OR REPLACE PROCEDURE sp_upd_suppressed_emails( A_LIMIT_BULK IN PLS_INTEGER DEFAULT 20 ...
- legend2---数据字段没有默认值错误:SQLSTATE[HY000]: General error: 1364 Field 'h_21_injury_limit' doesn't have a default value
legend2---数据字段没有默认值错误:SQLSTATE[HY000]: General error: 1364 Field 'h_21_injury_limit' doesn't have a ...
- @Aspect 注解切面解析
注解切面解析 注解切面解析器 /** * 注解切面解析器 */ public class BeanFactoryAspectJAdvisorsBuilder { /** * Bean 工厂 */ pr ...