URAL1079:Maximum
2013-11-30 21:29
267 查看
http://acm.timus.ru/problem.aspx?space=1&num=1079
Consider the sequence of numbers ai,
i = 0, 1, 2, …, which satisfies the following requirements:
a0 = 0
a1 = 1
a2i = ai
a2i+1 = ai + ai+1
for every i = 1, 2, 3, … .
Write a program which for a given value of n finds the largest number among the numbers
a0, a1, …, an.
n (1 ≤ n ≤ 99 999). The last line of input contains 0.
水题,按照公式打表即可
Consider the sequence of numbers ai,
i = 0, 1, 2, …, which satisfies the following requirements:
a0 = 0
a1 = 1
a2i = ai
a2i+1 = ai + ai+1
for every i = 1, 2, 3, … .
Write a program which for a given value of n finds the largest number among the numbers
a0, a1, …, an.
Input
You are given several test cases (not more than 10). Each test case is a line containing an integern (1 ≤ n ≤ 99 999). The last line of input contains 0.
Output
For every n in the input write the corresponding maximum value found.Sample
input | output |
---|---|
5100 | 34 |
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; __int64 a[1000000]; __int64 hash[1000000]; int main() { int i,j,n; __int64 maxn; a[0] = 0; hash[0] = 0; a[1] = 1; hash[1] = 1; maxn = 1; for(i = 2; i<=999999; i++) { if(i%2) { j = (i-1)/2; a[i] = a[j]+a[j+1]; } else a[i] = a[i/2]; if(a[i]>maxn) maxn = a[i]; hash[i] = maxn; } while(~scanf("%d",&n) && n) { printf("%I64d\n",hash ); } return 0; }
相关文章推荐
- Ural1079-Maximum
- URAL 1079 Maximum 递推
- Ural 1079 - Maximum
- URAL1079
- 51nod 1062 && URAL 1079 Maximum RMQ
- URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)
- ural 1146. Maximum Sum dp
- Ural 1119 Metro
- 【URAL 1635】Mnemonics and Palindromes(区间DP+记录路径)
- Leetcode Maximum Subarray
- UVA 10827 Maximum sum on a torus(环面上的最大子矩阵和)
- 【二叉树的递归】02二叉树的最大深度【Maximum Depth of Binary Tree】
- tomcat启动中提示 - consider increasing the maximum size of the cache
- 调用WebServiceWebService提示The maximum string content length quota (8192) has been exceeded while reading XML data的解决办法
- URAL 1137 Bus Routes(欧拉回路路径)
- cugb.20140417 (ural 1961 - 1970)
- Codevs 1079 回家 最短路 spfa || dijkstra
- ural1057 Amount of Degrees
- URAL 1160 Network(最小生成树)
- URAL 1018 Binary Apple Tree(树形dp入门题)