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)的更多相关文章

  1. UVA 100 - The 3n+1 problem (3n+1 问题)

    100 - The 3n+1 problem (3n+1 问题) /* * 100 - The 3n+1 problem (3n+1 问题) * 作者 仪冰 * QQ 974817955 * * [问 ...

  2. UVa 100 - The 3n + 1 problem(函数循环长度)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  3. 【转】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 / ...

  4. 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 ...

  5. UVa Problem 100 The 3n+1 problem (3n+1 问题)

    参考:https://blog.csdn.net/metaphysis/article/details/6431937 #include <iostream> #include <c ...

  6. 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+ ...

  7. 100-The 3n + 1 problem

    本文档下载 题目: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pro ...

  8. OpenJudge/Poj 1207 The 3n + 1 problem

    1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...

  9. The 3n + 1 problem

    The 3n + 1 problem Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) ...

随机推荐

  1. Flask – SQLite:增加成员

    目录 简介 结构 展示 技术 运行 代码 创建数据库表单 views视图 models模块 home主页 list列表页 result消息结果页 studentst添加成员 简介 结构 $ tree ...

  2. IDG资本全球拼图:近10年揽26家独角兽,最敢出手VC再造"VC+"

    IDG资本全球拼图:近10年揽26家独角兽,最敢出手VC再造"VC+" 2017-04-01 15:33   两天前,IDG资本合伙人过以宏提出的“VC+”,又有了新的内涵——全球 ...

  3. 从0开始学习 GitHub 系列之「03.Git 速成」

    前面的 GitHub 系列文章介绍过,GitHub 是基于 Git 的,所以也就意味着 Git 是基础,如果你不会 Git ,那么接下来你完全继续不下去,所以今天的教程就来说说 Git ,当然关于 G ...

  4. 【JZOJ3295】【SDOI2013】泉(spring)

    ╰( ̄▽ ̄)╭ 济南市"泉历史研究小组"依据济南特有的泉脉关系将济南的泉水分为六个区域,分别是市中区.历下区.天桥区.槐荫区.历城区.长清区. 作为光荣的济南泉历史研究小组中的一员 ...

  5. oracle-Normal

    从shutdown normal命令发布起, 禁止建立任何新的oracle连接. 数据库将等到所有用户都被断开后再继续关闭过程. 等待当前所有已连接的用户断开与数据库的连接

  6. jQuery事件大全(真的很全)

    DOM Attribute $("p").addClass(css中定义的样式类型); 给某个元素添加样式$("img").attr({src:"te ...

  7. Directx11教程(18) D3D11管线(7)

    原文:Directx11教程(18) D3D11管线(7) 光栅化阶段(RS)之后,将进入PS/OM阶段. 参考外文资料:http://fgiesen.wordpress.com/2011/07/01 ...

  8. padas操作

    1.从excel读取数据 pd.read_excel('naifen.xlsx') 2.保存为excel pd.to_excel('bb.xlsx') 3.统计某一列重复数据 df.groupby([ ...

  9. JAVA代码规范 标签: java文档工作 2016-06-12 21:50 277人阅读 评论(5) 收藏

    开始做java的ITOO了,近期的工作内容就是按照代码规范来改自己负责的代码,之前做机房收费系统的时候,也是经常验收的,甚至于我们上次验收的时候,老师也去了.对于我们的代码规范,老师其实是很重视的,他 ...

  10. Java练习 SDUT-3849_分数四则运算

    分数四则运算 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 编写程序,实现两个分数的加减法 Input 输入包含多行数 ...