ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1079. Maximum

Samsonov Ivan not simple AC 0.001s and 130 kb [2] // Problem 1079. Maximum 21 Sep 2005 04:00

#include <iostream>
int n,x;
int a[10];
int i,t;

int _max(int s1,int s2,int x)
{
    if (x==n)
        return s1+s2;
    else {
        int t1,t2;
        if (x*2-1<=n)
            t1 = _max(s1,s2+s1,x*2-1);
        else
            t1 = 0;
        if (x*2+1<=n)
            t2 = _max(s1+s2,s2,x*2+1);
        else
            t2 = 0;
        if ((t1==t2)&&(t2==0))
            return s1+s2;
        else
            return t1>t2?t1:t2;
    }
}

int main()
{
    std::cin >> n;
    i = 0;
    while (n){
        if (n==2)
            a[i] = 1;
        else
        if (n==1)
            a[i] = 1;
        else
        if (n==0)
            a[i] = 0;
        else
            a[i] = _max(1,1,3);
        std::cin >> n;
        i++;
    }
    for (n = 0;n<i;n++)
        std::cout << a[n] << "\n";

    return 0;
}
João Víctor Rocon Maia Re: not simple AC 0.001s and 130 kb [1] // Problem 1079. Maximum 9 Sep 2008 10:08
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
        unsigned int i, v[100000];
        v[0] = 0;
        v[1] = 1;
        for(i=2;i<100000;i++){
                if(i%2==0) v[i] = v[i/2];
                else v[i] = v[(i-1)/2] + v[(i-1)/2+1];
        }
        unsigned int n;
        while(cin >> n){
                if(n!=0) cout << *max_element(v, v+n+1) << endl;
        }
        return 0;
}
Abid29 Re: not simple AC 0.001s and 130 kb // Problem 1079. Maximum 22 Jun 2019 13:35
/* its not accepted. whats wrong with it?? WA on test 4  */
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long n=1000,i,k;
    long long a[100000];
    a[0]=0,a[1]=1;
    for(i=2;i<n;i=i+2){
            k=i/2;
        a[i]=a[k],a[i+1]=a[k]+a[k+1];
    }
    cin>>n;
    while(n){
            cout<<*max_element(a,a+n+1)<<endl;
        cin>>n;
    }
}

Edited by author 22.06.2019 13:37

Edited by author 22.06.2019 13:37

Edited by author 22.06.2019 13:39