charsyam
BAN USER#include <stdio.h>
#include <iostream>
using namespace std;
int cont(int k){
int j = k/2;
if( k%2 == 0 ){
j = k/2-1;
}
return j;
}
int main( int argc, char *argv[] )
{
int j;
cin >> j;
if( j == 2 || j == 3 ){
printf("K: {%d}\n", j);
return 0;
}
int t = cont(j);
for( int k = j; k >= 2 && k > t; k-- ){
if( k == j ){
printf("K: {%d}\n", j);
} else {
if( j-k > 1 )
printf("K: {%d,%d}\n", j-k, k );
}
}
return 0;
}
Very simple solutiion ^^
int find_node2( Node *node, int value1, int value2 ) {
int ret = 0;
if( node->data == value1 || node->data == value2 ) {
ret++;
}
if( node->left ) {
ret += find_node2( node->left, value1, value2 );
}
if( node->right ) {
ret += find_node2( node->right, value1, value2 );
}
if( ret == 2 ){
printf("this node is common parent: %d(%d,%d)\n",
node->data, value1, value2);
}
return ret > 0 ? 1 : 0;
}
somewhat strange solution but it works. just using combination. not DP
not elegant.
- charsyam November 12, 2012