ural 1079. Maximum
2015-05-05 20:24
253 查看
Memory limit: 64 MB
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.
Problem Author: Emil Kelevedzhiev
Problem Source: Winter Mathematical Festival Varna '2001 Informatics Tournament
Tags: (
show tags for all problems
)
给你一个n,找出一到n里面a[i]最大值,,当然普通暴力必然超时,另外开一个数组存所有的最大值便好了 。
复杂度是O(n)。
1079. Maximum
Time limit: 2.0 secondMemory limit: 64 MB
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 |
---|---|
5 10 0 | 3 4 |
Problem Source: Winter Mathematical Festival Varna '2001 Informatics Tournament
Tags: (
show tags for all problems
)
给你一个n,找出一到n里面a[i]最大值,,当然普通暴力必然超时,另外开一个数组存所有的最大值便好了 。
复杂度是O(n)。
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define MAXN 100000 int a[MAXN]; int sum[MAXN]; int main() { int i; int ans=3; a[0]=0; a[1]=1; a[2]=1; a[3]=2; a[4]=1; a[5]=3; sum[0]=0; sum[1]=1; sum[2]=1; sum[3]=2; sum[4]=2; sum[5]=3; for(i=6; i<100000; i++) { if(i&1) a[i]=a[i/2]+a[i/2+1]; else a[i]=a[i/2]; ans=max(ans,a[i]); sum[i]=ans; } int n; while(cin>>n,n) cout<<sum <<endl; return 0; }
相关文章推荐
- URAL 1079. Maximum
- URAL 1012 K-based Numbers. Version 2(DP+高精度)
- URAL - 1019 - Line Painting(离散化+线段树)
- Ural 1463. Happiness to People!
- URAL1826. Minefield 题解
- ural 1076 KM求最小权匹配
- ural 1143. Electric Path(凸包上最短哈密顿路径)
- URAL 1877 Bicycle Codes
- URAL 1880 Psych Up's Eigenvalues multiset水题
- Ural 1260 A nudnik photographer(DP)
- URAL 1747 Kingdom Inspection 容斥原理
- ural1109(二分图模板)
- Ural 1068 sum
- URAL——1005 stone pile
- Ural 1982 Electrification Plan (prim最小生成树)
- URAL 1586 Threeprime Numbers(DP)
- ural Bicolored Horses(二维dp)
- URAL 1204. Idempotents 扩展欧几里德
- URAL 1362. Classmates 2
- URAL 1737 Mnemonics and Palindromes 3 构造