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

what is the wrong in this solution to the 1079 problem.
Posted by syamsundar 30 May 2011 11:45
#include <stdio.h>
#include <time.h>
//#include <windows.h> // GetTickCount()

int fun(int n);
int main()
{
    int n,max,t,x;
    long te=0, ts=0;

    printf("\n Enter the Number..\n");
    scanf("%d",&n);
    x=n;
    max=0;

  // ts = GetTickCount();

   if(n%2==0)
   n=n-1;
    while(n>=0)
    {
        if((t=fun(n))>max)
         max=t;
         n=n-2;

    }

        printf("\n %d %d \n",x,max);
   // te = GetTickCount();
   // printf("\n ts=%ld \n",te);
   //printf("%d ms\n", te - ts);


   // getch();



}

int fun(int n)
{
    if(n==0)return 0;
    else if(n==1)return 1;
    else if(n%2==0)return(fun(n/2));
    else if(n%2==1)return(fun((n-1)/2)+fun((n-1)/2+1));

    return 0;
}
Re: what is the wrong in this solution to the 1079 problem.
Posted by syamsundar 30 May 2011 11:48