1079. Maximum

11 篇文章 0 订阅
1079. Maximum
Time limit: 2.0 second
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.
Input
You are given several test cases (not more than 10). Each test case is a line containing an integer n (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 Author: Emil Kelevedzhiev

Problem Source: Winter Mathematical Festival Varna '2001 Informatics Tournament


#include <iostream>

#include <vector>

using namespace std;


void Maximum(int n){

    vector<int> nums;

    nums.insert(nums.end(), 0);

    nums.insert(nums.end(), 1);

    if(n<=1){

        cout<<nums[n]<<endl;

        return;

    }

    int max = nums[1];

    for(int i = 2 ; i <= n ; i++){

        if(i%2==0){

            nums.insert(nums.end(), nums[i/2]);

        }

        else{

            nums.insert(nums.end(), (nums[(i-1)/2]+nums[((i-1)/2) + 1]));

        }

        if(nums[i]>max){

            max = nums[i];

        }

    }

    cout<<max<<endl;

    

}



int main(){

    vector<int> inputnum;

    int n;

    cin>>n;

    while (n!=0) {

        inputnum.insert(inputnum.end(), n);

        cin>>n;

    }

    for(int i = 0 ; i < inputnum.size() ; i++){

        Maximum(inputnum[i]);

    }

    return 0;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值