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 1149. Sinus Dances

daftcoder [Yaroslavl SU] Nice recursive functions [2] // Problem 1149. Sinus Dances 20 Mar 2010 18:21
I thought i'll never get AC at this problem, but after some time i wrote that very nice (as for me ^___^) functions doing the work.

void a( int n, int k )
{
-printf("sin(%d",k);
-if ( k < n )
-{
--if ( k % 2 )
---printf("-");
--else
---printf("+");
--a( n, k + 1 );
-}
-printf(")");
}

void s( int n, int k )
{
-if ( k < n )
-{
--printf("(");
--s( n, k + 1 );
--printf(")");
-}
-a( n - k + 1, 1 );
-printf("+%d",k);
}

For answer just need to call s( n, 1 ).
Good luck!

Edited by author 20.03.2010 18:23
pusho4eg Re: Nice recursive functions // Problem 1149. Sinus Dances 25 Apr 2011 00:48
void s(int n, int k)
{ printf("sin(%d",k);
  if (n!=k)
  { putchar(((k&1)<<1)+43);
    s(n,++k);
  }
  putchar(')');
}

void p(int n, int k)
{ if (k>1)
  {  putchar('(');
     p(n,k-1);
  }
  s(k,1);
  printf("+%d",n+1-k);
  if (k<n) putchar(')');
}

my algorithm... for answer p(n,n)
Shah Habibul Imran Re: Nice recursive functions // Problem 1149. Sinus Dances 11 Oct 2018 12:30
Thanks, I was stuck in the recursion for Sn. :)