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 ...
随机推荐
- Kotlin使用率达35%,Java要退位了?
在今年的Google I/O大会上,关于Kotlin,Google只说了只言片语: 在过去一年里,有35%的专业Android开发者在使用Kotlin,其中95%的开发者都对Kotlin非常满意. 之 ...
- python 线程模块
Python通过两个标准库thread和threading提供对线程的支持.thread提供了低级别的.原始的线程以及一个简单的锁. threading 模块提供的其他方法: threading.cu ...
- PHP大文件分片上传断点续传实例源码
1.使用PHP的创始人 Rasmus Lerdorf 写的APC扩展模块来实现(http://pecl.php.net/package/apc) APC实现方法: 安装APC,参照官方文档安装,可以使 ...
- CQOI2010 传送带
题目链接:戳我 分别枚举线段AB上的出发点,和线段CD上的到达点,然后时间直接计算,取min就可以了. 但是这样子显然会T飞,(相当于1e5的平方吧?)所以我们进一步考虑性质. 然后打表(或者感性理解 ...
- memset设置最大值
初始化为最大值 memset(mp,0x7f,sizeof(mp));
- CCA(典型相关分析)
https://www.cnblogs.com/pinard/p/6288716.html
- HDU 6012 Lotus and Horticulture(离散化)
题目代号:HDU 6012 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6012 Lotus and Horticulture Time Limit: ...
- Spring Boot教程(十)异步方法测试
测试 测试代码如下: @Component public class AppRunner implements CommandLineRunner { private static final Log ...
- 关于tomcat的server.xml里host节点配置的一些说明
其实对这个一直搞不清楚,后来公司的网站遭遇与IIS进行整合,然后上面有几个应用需要进行配置,所以对tomcat的server.xml进行了一些深入的了解 Host的节点主要是起一个对域名解析到那个虚拟 ...
- springBoot 配置url 访问图片
需要添加依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...