zoukankan      html  css  js  c++  java
  • Ural 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.

    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

    inputoutput
    5
    10
    0
    
    3
    4
    
    Problem Author: Emil Kelevedzhiev
    Problem Source: Winter Mathematical Festival Varna '2001 Informatics Tournament
    // Ural Problem 1079. Maximum
    // Verdict: Accepted  
    // Submission Date: 14:33:08 15 Jan 2014
    // Run Time: 0.031s
    //  
    // 版权所有(C)acutus   (mail: acutus@126.com) 
    // 博客地址:http://www.cnblogs.com/acutus/
    // [解题方法]  
    // 简单题模拟题
    // 注意:最大项有可能是奇数项
    
    #include<stdio.h>
    
    long long a[100000], b[100000];
    
    void solve()
    {
        int i, j, max, n;
        a[0] = b[0] = 0;
        a[1] = b[1] = 1;
        max = 1;
        for(i = 2; i < 100000; i++) {
            if(i % 2) {
                j = (i - 1) >> 1;
                a[i] = a[j] + a[j + 1];
            } else {
                a[i] = a[i >> 1];
            }
            if(a[i] > max)
                max = a[i];
            b[i] = max;
        }
        while(scanf("%d", &n) && n) {
            printf("%lld
    ", b[n]);
        }
    }
    
    int main()
    {
        solve();
        return 0;
    }
  • 相关阅读:
    idea 使用
    scala
    Java开发工具
    ActiveMQ基础
    Java 多线程实战
    Java 内部类和Lambda
    Spring 学习
    平滑重启php
    opcache
    redis的hscan命令
  • 原文地址:https://www.cnblogs.com/acutus/p/3520750.html
Copyright © 2011-2022 走看看