[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,... ...
随机推荐
- [LeetCode]题解(python):072-Edit Distance
题目来源: https://leetcode.com/problems/edit-distance/ 题意分析: word1最少通过多少步可以变成word2.word1只能进行一下的操作.a)插入一个 ...
- inline-block 垂直居中
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【转】vs2008中leptonica-1.68安装配置
tesseract ocr挺不好配置的,找到一篇不错的文章,分享如下:http://hi.baidu.com/ever8936/blog/item/6998e1196b1d0161dab4bd8f.h ...
- ftp一些东东
ftp如果绑定域名 登录时登录名应该写成 域名|用户名
- 转:js不同类型对象的比较规则
Type(x) Type(y) Result type(x)==type(y) x===y otherwise... false null undefined true undefined null ...
- C++ 100款开源界面库 (10)
(声明:Alberl以后说到开源库,一般都是指著名的.或者不著名但维护至少3年以上的.那些把代码一扔就没下文的,Alberl不称之为开源库,只称为开源代码.这里并不是贬低,像Alberl前面那个系列的 ...
- Qtwebkit配置,设置交叉编译环境 - croop520的专栏 - 博客频道 - CSDN.NET
Qtwebkit配置,设置交叉编译环境 - croop520的专栏 - 博客频道 - CSDN.NET Qtwebkit配置,设置交叉编译环境 分类: Qt Webkit 2012-04-12 15: ...
- 开发板-PC机(宿主机)-虚拟机(VM)之间网络通信设置方法及须要注意的问题
1.不使用路由器交换机 硬件连接: 使用网线将开发板和PC机相连 串口线将PC机和开发板相连 使用命令: ifconfig -a 串口控制端查看开发板的网络配置 route -n 串口控制端查看开发板 ...
- ofbiz学习笔记
最新稳定版apache-ofbiz-13.07.02 最新源码ofbiz-release14.12 ant load-demo 载入演示样例数据 ant load-seed 仅仅载入种子数据 ant ...
- Backbone入门教程
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...