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. Leetcode575.Distribute Candies分糖果

    给定一个偶数长度的数组,其中不同的数字代表着不同种类的糖果,每一个数字代表一个糖果.你需要把这些糖果平均分给一个弟弟和一个妹妹.返回妹妹可以获得的最大糖果的种类数. 示例 1: 输入: candies ...

  2. jquery源码学习(三)—— jquery.prototype主要属性和方法

    上次我们学习了jquery中的主要对象jQuery和一些变量,现在我们开始学习jquery的原型 98行声明了jQuery.fn = jQuery.prototype = {} 285行jQuery. ...

  3. java如何访问memcache

    1       Memcache是什么 Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的 ...

  4. arcgis增大缩放级别

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. fedora安装mod_python

    3.1 Installing mod_python To install mod_python, we simply run: yum install mod_python 3.2 Configuri ...

  6. SpringBoot实战之异常处理篇

    在互联网时代,我们所开发的应用大多是直面用户的,程序中的任何一点小疏忽都可能导致用户的流失,而程序出现异常往往又是不可避免的,那该如何减少程序异常对用户体验的影响呢?其实方法很简单,对异常进行捕获,然 ...

  7. POJ3697

    /* Memory Time 7096K 2641MS */ #include <iostream> #include <string> using namespace std ...

  8. SQLServer —— EXISTS子查询

    一.删除数据库 use master go if exists (select * from sysdatabases where name = 'Demo') drop database Demo ...

  9. day39-Spring 02-AOP的概述

     横向抽取的机制其实就是代理机制.对UserDao生成一个代理类:UserDaoProxy.被代理对象和代理对象它俩实现相同的接口它俩肯定是平级的,这就是横向抽取的机制.如果这时候调用UserDao的 ...

  10. oralce触发器

    n  触发器的分类 DML(insert,delete,update)触发器 DDL(create table ,create view...drop...)触发器 系统触发器(与系统相关的触发器,比 ...