Skip to content

Instantly share code, notes, and snippets.

@mob5566
Created May 21, 2015 08:32
Show Gist options
  • Save mob5566/71c4d84f90e88108ef49 to your computer and use it in GitHub Desktop.
Save mob5566/71c4d84f90e88108ef49 to your computer and use it in GitHub Desktop.
10223 - How many nodes ?
/**
* Tittle: 10223 - How many nodes ?
* Author: Cheng-Shih, Wong
* Date: 2015/05/21
*/
// include files
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
// definitions
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i )
#define clr(x,v) memset( x, v, sizeof(x) )
typedef long long ll;
typedef map<ll,int> MLLI;
// declarations
ll n;
MLLI treeToNode;
ll catalan[50];
// functions
// main function
int main( void )
{
// init
treeToNode.clear();
catalan[0] = 1;
treeToNode[catalan[0]] = 0;
FOR( i, 0, 19 ) {
catalan[i+1] = catalan[i]*(4*i+2)/(i+2);
treeToNode[catalan[i+1]] = i+1;
}
// input
while( scanf( "%lld", &n )==1 ) {
// output
printf( "%d\n", treeToNode[n] );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment