51nod 2级算法题-1062
来源:互联网 发布:手机模拟器网络加速器 编辑:程序博客网 时间:2024/06/05 08:38
1062 序列中最大的数
题目来源: Ural 1079
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题
有这样一个序列a:a[0] = 0a[1] = 1a[2i] = a[i]a[2i+1] = a[i] + a[i+1]输入一个数N,求a[0] - a[n]中最大的数。a[0] = 0, a[1] = 1, a[2] = 1, a[3] = 2, a[4] = 1, a[5] = 3, a[6] = 2, a[7] = 3, a[8] = 1, a[9] = 4, a[10] = 3。例如:n = 5,最大值是3,n = 10,最大值是4。
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10)第2 - T + 1行:T个数,表示需要计算的n。(1 <= n <= 10^5)
Output
共T行,每行1个最大值。
Input示例
2510
Output示例
34
数据太水,直接预处理出数组来。
#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>#include <queue>#include <stack>using namespace std;#define endl "\n"const int maxn=100100;int a[maxn];void Init(){ memset(a,0,sizeof(a)); a[1]=1; a[2]=1; for(int i=3;i<maxn;i++){ if(i%2==0){ a[i]=a[i/2]; }else{ a[i]=a[i/2]+a[i/2+1]; } } int Max=0; for(int i=0;i<maxn;i++){ if(a[i]>Max){ Max=a[i]; } a[i]=Max; } return ;}int main (){ ios::sync_with_stdio(false); Init(); int T; cin>>T; while(T--){ int n; cin>>n; cout<<a[n]<<endl; }}
0 0
- 51nod 2级算法题-1062
- 51nod 2级算法题-1007
- 51nod 2级算法题-1010
- 51nod 2级算法题-1014
- 51nod 2级算法题-1050
- 51nod 2级算法题-1092
- 51nod 2级算法题-1095
- 51nod 2级算法题-1119
- 51nod 2级算法题-1126
- 51nod 2级算法题-1133
- 51nod 2级算法题-1279
- 51nod 2级算法题-1315
- 51nod 2级算法题-1428
- 【模拟】1432 独木舟【51nod】【难度:2级算法题】
- 51nod 1级算法题
- 51nod 3级算法题-1065
- 51nod 5级算法题
- 【贪心+优先队列】1428 活动安排问题【51nod】【难度:2级算法题】
- 高效加载大图片之Lrucache使用
- 更新ruby出现的Error running '__rvm_make -j 1',问题解决方法
- 堆栈溢出问题 调试到位置(test dword ptr [eax],eax ; probe page.)局部数组变量定义所分配的最大空间为1M
- java selenium (十二) 操作弹出窗口
- EDAS入门学习
- 51nod 2级算法题-1062
- OpenGL学习笔记2:绘制和混合
- tensorflow调参总结(不断更新中)
- Android--菜单的使用介绍
- git常用命令
- Spring Boot核心-基本配置
- java selenium (十三) 智能等待页面加载完成
- 移动端常用meta及问题
- 三次握手和四次挥手