uva 100 The 3n + 1 problem (RMQ)
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=36
预处理,RMQ求区间最大值。
代码如下:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; typedef long long LL;
const int N = ;
const int M = ;
int pre[N], RMQ[M][N >> ];
int dfs(LL n) {
if (n <= ) cout << n << endl;
if (n < N && pre[n]) return pre[n];
int tmp;
if (n & ) tmp = dfs(n * + ) + ;
else tmp = dfs(n >> ) + ;
if (n < N) pre[n] = tmp;
return tmp;
} void PRE() {
pre[] = ;
for (int i = , end = N >> ; i < end; i++) if (pre[i] == ) dfs(i);
// for (int i = 1; i < 20; i++) cout << i << ' ' << pre[i] << endl;
// prepare RMQ
for (int i = , end = N >> ; i < end; i++) RMQ[][i] = pre[i];
for (int i = ; i < M; i++) {
for (int j = , end = (N >> ) - ( << i); j <= end; j++) {
RMQ[i][j] = max(RMQ[i - ][j], RMQ[i - ][j + ( << i - )]);
}
}
} int query(int l, int r) {
if (l > r) swap(l, r);
int ep = (int) log2((double) r - l + );
return max(RMQ[ep][l], RMQ[ep][r - ( << ep) + ]);
} int main() {
PRE();
int l, r;
while (cin >> l >> r) cout << l << ' ' << r << ' ' << query(l, r) << endl;
return ;
}
——written by Lyon
uva 100 The 3n + 1 problem (RMQ)的更多相关文章
- UVA 100 - The 3n+1 problem (3n+1 问题)
100 - The 3n+1 problem (3n+1 问题) /* * 100 - The 3n+1 problem (3n+1 问题) * 作者 仪冰 * QQ 974817955 * * [问 ...
- UVa 100 - The 3n + 1 problem(函数循环长度)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- 【转】UVa Problem 100 The 3n+1 problem (3n+1 问题)——(离线计算)
// The 3n+1 problem (3n+1 问题) // PC/UVa IDs: 110101/100, Popularity: A, Success rate: low Level: 1 / ...
- PC/UVa 题号: 110101/100 The 3n+1 problem (3n+1 问题)
The 3n + 1 problem Background Problems in Computer Science are often classified as belonging to a ...
- UVa Problem 100 The 3n+1 problem (3n+1 问题)
参考:https://blog.csdn.net/metaphysis/article/details/6431937 #include <iostream> #include <c ...
- UVA 100 The 3*n+1 problem
UVA 100 The 3*n+1 problem. 解题思路:对给定的边界m,n(m<n&&0<m,n<1 000 000);求X(m-1<X<n+ ...
- 100-The 3n + 1 problem
本文档下载 题目: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pro ...
- OpenJudge/Poj 1207 The 3n + 1 problem
1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...
- The 3n + 1 problem
The 3n + 1 problem Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
随机推荐
- OSGi教程:Class Space Consistency
此教程基于OSGi Core Release 7 OSGi类空间的一致性 详细内容上面英文教程有详细解答 下面主要是一些个人见解,若有不当之处,欢迎指出: "Class space cons ...
- JZOJ 平衡的子集
Description 夏令营有N个人,每个人的力气为M(i).请大家从这N个人中选出若干人,如果这些人可以分成两组且两组力气之和完全相等,则称为一个合法的选法,问有多少种合法的选法? Input 第 ...
- ML面试1000题系列(31-40)
本文总结ML面试常见的问题集 转载来源:https://blog.csdn.net/v_july_v/article/details/78121924 31.下列哪个不属于CRF模型对于HMM和MEM ...
- CLTPHP5.0发布
CLTPHP内容管理系统,包含系统设置,权限管理,模型管理,数据库管理,栏目管理,会员管理,网站功能,模版管理,微信管理等相关模块. CLTPHP内容管理系统=ThinkPHP5+layuiAdm ...
- 【python小随笔】Django+错误日志(配置Django报错文件指定位置)
1: 自定义日志文件.py----------几个文件需要创建日志,就需要重新定义几份 # 定义一个日志文件 创建一个操作日志对象logger file_1 = logging.FileHandle ...
- BootstrapValidation一些tips
BootstrapValidation一些tips:1. callback的用法 如果你有一些特别的检查需要,比如两个元素必需有一个有值,你可以在两个元素上加上callback,例:sel和cb必需有 ...
- 链表经典题Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...
- yum源配置及详解
红帽系列中,进行软件安装可以有三种方法,编译安装,rpm包安装,和yum源安装.其中yum方法安装最简单,因为它可以自动解决软件包之间的依赖关系... 一.常用yum源 yum源可以来源于多种文件 ...
- SQLServer —— 流程控制语句
一.IF - ELSE 语法: IF(条件) BEGIN 语句1 语句2 ... END ELSE BEGIN 语句1 语句2 ... END 说明: ELSE是可选部分,如果有多条语句,才需要BEG ...
- 【JZOJ4804】【NOIP2016提高A组模拟9.28】成绩调研
题目描述 输入 输出 样例输入 5 3 1 2 3 1 2 1 2 1 1 1 1 样例输出 4 数据范围 解法 考虑设置左指针l和右指针r: 维护[l,r]的关于等第的桶. 初始l=r=0: 每次右 ...