[Swust OJ 137]--波浪数(hash+波浪数构造)
题目链接:http://acm.swust.edu.cn/problem/137/
类似的可以定义三重波浪数,三重波浪数在三种不同的进制中都是波浪数,甚至还有四重波浪数,如十进制300=606(七进制)=363(九进制)=454(八进制)=1A1(十三进制)…,你的任务就是在指定范围内找出双重、三重、四重波浪数。
| 10 11 190000 960000 2 |
|
191919
383838
575757
767676
959595
|
#include<iostream>
using namespace std;
int x, y, a, b, k;
short Hash[];//占两个字节,减少内存
int Len(int x, int k){
int cnt = ;
while (x){
x /= k;
++cnt;
}
return cnt;
}
int make(int a, int b, int len, int k){
//在k进制范围下计算构造波浪数的值
int x = , i;
for (i = ; i <= len; i++){
if (i & )
x = x*k + a;
else
x = x*k + b;
}
return x;
}
void Search(int k){
int l = Len(a, k), r = Len(b, k), i, j, u;
//数字首位不为零,构造波浪数,减少计算次数
for (i = ; i < k; i++)
for (j = ; j < k; j++){
if (i == j) continue;
for (u = l; u <= r; u++){
int num = make(i, j, u, k);
if (num >= a&&num <= b) Hash[num]++;
}
}
}
int main(){
cin >> x >> y >> a >> b >> k;
for (int i = x; i <= y; i++)
Search(i);
for (int i = a; i <= b; i++)
if (Hash[i] == k)
cout << i << endl;
return ;
}
[Swust OJ 137]--波浪数(hash+波浪数构造)的更多相关文章
- [Swust OJ 797]--Palindromic Squares(回文数水题)
题目链接:http://acm.swust.edu.cn/problem/797/ Time limit(ms): 1000 Memory limit(kb): 10000 Description ...
- [Swust OJ 610]--吉祥数
题目链接:http://acm.swust.edu.cn/problem/610/ Time limit(ms): 1000 Memory limit(kb): 65535 Description ...
- 九度OJ 1060:完数VS盈数 (数字特性)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5590 解决:2093 题目描述: 一个数如果恰好等于它的各因子(该数本身除外)子和,如:6=3+2+1.则称其为"完数" ...
- 九度oj 题目1060:完数VS盈数
题目1060:完数VS盈数 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6461 解决:2426 题目描述: 一个数如果恰好等于它的各因子(该数本身除外)子和,如:6=3+2+1.则称其 ...
- [Swust OJ 404]--最小代价树(动态规划)
题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535 Des ...
- SWUST OJ NBA Finals(0649)
NBA Finals(0649) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128 Descri ...
- [Swust OJ 1139]--Coin-row problem
题目链接: http://acm.swust.edu.cn/contest/0226/problem/1139/ There is a row of n coins whose values are ...
- [Swust OJ 409]--小鼠迷宫问题(BFS+记忆化搜索)
题目链接:http://acm.swust.edu.cn/problem/409/ Time limit(ms): 1000 Memory limit(kb): 65535 Description ...
- [Swust OJ 541]--排列字典序问题
题目链接:http://acm.swust.edu.cn/problem/0541/ Time limit(ms): 2000 Memory limit(kb): 65535 n个元素{1,2,... ...
随机推荐
- jackson的简单实用实例(json)
一个json格式的字符串比如: {"status":10001,"code":"HDkGzI","pubkey":&qu ...
- The introduction to Web.config of ASP.NET #Reprinted#
花了点时间整理了一下ASP.NET Web.config配置文件的基本使用方法.很适合新手参看,由于Web.config在使用很灵活,可以自定义一些节点.所以这里只介绍一些比较常用的节点. <? ...
- LintCode- 删除排序数组中的重复数字
题目描述: 给定一个排序数组,在原数组中删除重复出现的数字,使得每个元素只出现一次,并且返回新的数组的长度. 不要使用额外的数组空间,必须在原地没有额外空间的条件下完成. 样例 给出数组A =[1,1 ...
- C# 方法的可选参数、命名参数
原文 http://www.cnblogs.com/lonelyxmas/admin/EditPosts.aspx?opt=1 C#方法的可选参数是.net 4.0最新提出的新的功能,对应简单的重载可 ...
- HDU 2451 Simple Addition Expression
题目大意:有一个关于 简单加法表达式 的定义告诉你,就是 选一个数字i 如果 i+(i+1)+(i+2) 它的和,没有任何一位进位的话,那就是 一个i的简单加法表达式,求小于n的表达式数目. 题 ...
- Parsing HTML with C++ (using Qt preferably) - Stack Overflow
Parsing HTML with C++ (using Qt preferably) - Stack Overflow Parsing HTML with C++ (using Qt prefera ...
- Uber选拔专车司机:五年以上驾驶经验 两小时视频培训
摘要:说起当时下流行打车软件Uber的司机,还得从春节前在上海一次打车说起.那几天,记者在上海某商场逛到打烊时间,大包小包拎着袋子根本腾不出手拦出租车,而商场门口的出租车临时停靠点更是挤满“血拼”而归 ...
- Scrambled Polygon(凸多边形,斜率)
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7805 Accepted: 3712 ...
- ActionScript3游戏中的图像编程(连载十七)
总文件夹:http://blog.csdn.net/iloveas2014/article/details/38304477 1.3.3 HSB与RGB之间的互转公式及HSL和HSV对色彩属性理解的异 ...
- 特殊集合(stack、queue、hashtable的示例及练习)
特殊集合:stack,queue,hashtable stack:先进后出,一个一个的赋值一个一个的取值,按照顺序. .count 取集合内元素的个数 .push() ...