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 ...
随机推荐
- Codecombat 游戏攻略(计算机科学三)2
第33关 逻辑之路 判断secretB 非真,走上面:否则,走下面(这里面要先自己进行逻辑判断)if…else语句或者这样用(不用自己进行判断) // 如果 secretB 非真,走上面:否则,走下面 ...
- 微信公众号发送告警Python脚本
调用该脚本,可以向微信公众号发生告警. #!/bin/env python #coding:utf-8 #Author: Hogan #Descript : 微信公众号发送告警脚本 import ur ...
- SpringBoot项目中,cookie的设置与销毁
cookie的设置与销毁 1.设置cookie /** * 设置一个cookie * @param response HttpServletResponse * @param name cookie的 ...
- BZOJ 4488: [Jsoi2015]最大公约数 暴力 + gcd
Description 给定一个长度为 N 的正整数序列Ai对于其任意一个连续的子序列 {Al,Al+1...Ar},我们定义其权值W(L,R )为其长度与序列中所有元素的最大公约数的乘积,即W(L, ...
- sh_04_累加求和
sh_04_累加求和 # 计算 0 ~ 100 之间所有数字的累计求和结果 # 0. 定义最终结果的变量 result = 0 # 1. 定义一个整数的变量记录循环的次数 i = 0 # 2. 开始循 ...
- CVPR 2018 DeepGlobe
在刚刚结束的CVPR2018: DeepGlobe Road Extraction Challenge(全球卫星图像道路提取)比赛中,北京邮电大学信息与通信工程学院模式识别实验室张闯老师指导的研究生周 ...
- Vue.js 使用 Font Awesome 小图标
1.安装 Font Awesome npm i --save @fortawesome/fontawesome-svg-core npm i --save @fortawesome/free-soli ...
- Redis缓存雪崩和缓存穿透等问题
穿透 缓存穿透是指查询一个一定不存在的数据,由于缓存是不命中时需要从数据库查询,查不到数据则不写入缓存,这将导致这个不存在的数据每次请求都要到数据库去查询,造成缓存穿透. 解决办法:①用一个bitma ...
- Spring Boot教程(十一) springboot程序构建一个docker镜像
准备工作 环境: linux环境或mac,不要用windows jdk 8 maven 3.0 docker 对docker一无所知的看docker教程. 创建一个springboot工程 引入web ...
- [LeetCode]-011-Roman_to_Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...