[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,... ...
随机推荐
- JQuery中回车键登陆
//点击回车键 //王东升/2015/3/11 document.onkeydown = function (event) { var e = event ? event : (window.even ...
- Servlet url-pattern优先级
完全匹配>目录匹配>扩展名匹配
- Android 开发笔记 “Sqlite数据库删除”
1.代码方式 Context.deleteDatabase(String databaseName);//删除某一数据库 2.设置里面 进入应用程序 ,然后清除数据就ok了
- [LeetCode]题解(python):096-Unique Binary Search Trees
题目来源: https://leetcode.com/problems/unique-binary-search-trees/ 题意分析: 给定一个整数n,返回所有中序遍历是1到n的树的可能. 题目思 ...
- 设置windows密码只存在NTLM-Hash下
修改注册表 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa 下添加名为"NoLMHash"的DWORD值,并设置为1 ...
- 26_Json_Example
JSON 很通用的处理数据的工具,各个语言都可以使用. 这个App就是把一个网上的用JSON格式保存的数据拿下来,然后保存到字典中,显示出来,用iOS自己的方法. 一定要记得写最后的那个 task.r ...
- 在windows下配置对github的操作--基本操作
一.下载安装 git for widows软件 git for widows 是专门用来在windows下操作 github的软件,提供bash(命令行) 和 gui两种方式. 在bash下,其实就是 ...
- android LinearLayout和RelativeLayout实现精确布局
先明确几个概念的区别: padding margin:都是边距的含义,关键问题得明白是什么相对什么的边距padding:是控件的内容相对控件的边缘的边距. margin :是控件边缘相对父空间的边距 ...
- grunt用来压缩前端脚本
grunt作为一个任务管理工具,提供丰富的插件和强大的自动化管理功能.需要安装node及npm. 主要使用到两个文件,一个是npm的依赖配置文件package.json { "name&qu ...
- 去除List列表中反复值(稍作调整,也适合于List<T> 和 List<?>)
方法一 循环元素删除 [c-sharp] view plaincopy public static void removeDuplicate(List list) { for ( int i = 0 ...