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) ...
随机推荐
- JavaScript 报错 注释
- 洛谷 1083 (NOIp2012) 借教室——标记永久化线段树 / 差分+二分
题目:https://www.luogu.org/problemnew/show/P1083 听说线段树不标记永久化会T一个点. 注意mn记录的是本层以下.带上标记的min! #include< ...
- asp.net技术(公共方法)
#region 获取 本周.本月.本季度.本年 的开始时间或结束时间 /// <summary> /// 获取开始时间 /// </summary> /// <param ...
- Android 对保存在 sharedpreference的重要数据进行编解码
有时候为了登录方便会将用户名和密码保存在 sharedpreference里面,可是如果不加以处理密码将以明文保存. 在Android中java层提供了工具类:android.util.Base64; ...
- 【JZOJ5086】【GDOI2017第四轮模拟day1】数列 折半搜索
题面 有一个长度为n 的排列,现在有一些位置的数已经模糊不清了,你只知道这个排列的逆序对个数是K,你能计算出总共有多少可能的排列吗? 对于100% 的数据,n <=10^3,K<=10^9 ...
- 手把手教你实现一个通用的jsonp跨域方法
什么是jsonp JSONP(JSON with Padding)是JSON的一种"使用模式",可用于解决主流浏览器的跨域数据访问的问题.由于同源策略,一般来说位于 server1 ...
- vue 数组遍历方法forEach和map的原理解析和实际应用
一.前言 forEach和map是数组的两个方法,作用都是遍历数组.在vue项目的处理数据中经常会用到,这里介绍一下两者的区别和具体用法示例. 二.代码 1. 相同点 都是数组的方法 都用来遍历数组 ...
- day38 19-Spring整合web开发
整合Spring开发环境只需要引入spring-web-3.2.0.RELEASE.jar这个jar包就可以了,因为它已经帮我们做好了. Spring整合web开发,不用每次都加载Spring环境了. ...
- 【itsdangerous】的加密解密原理(易懂版)
from itsdangerous import TimedJSONWebSignatureSerializer import time from itsdangerous import Signat ...
- Directx11教程(46) alpha blend(3)
原文:Directx11教程(46) alpha blend(3) 现在我们尝试改变box的贴图,使用一张带alpha的dds文件wirefence.dds, 用directx textu ...