void recursive(TreeNode *root, int hight, int &min)
    {
        if (root == NULL)
        {
            return;
        }
        
        hight++;
        if (root->left == NULL && root->right == NULL)
        {
            if (flag == 0)
            {
                min = hight;
                flag = 1;
            }
            else if (min > hight && flag == 1)
            {
                min = hight;
            }
        }
        
        recursive(root->left, hight, min);
        recursive(root->right, hight, min);
//        hight--;
    }
Esempio n. 2
0
int main ()
{
	char input[20];
	int testCaseRunning=1;
	while (gets(input))
	{
		printf("%4d. ",testCaseRunning++);
		char temp[100]="", output[100]="";
		unsigned long n = 0 ;
		int term = 1;
		if(strlen(input)>=9)
		{
			sprintf(temp,"%s",&input[strlen(input)-9]);
			input[strlen(input)-9] = '\0';
			sscanf(temp,"%lu",&n);
			recursive(n,term,output);
			term=2;
			if(strstr(output,"kuti")==NULL && strlen(output)!=0)
			{
				sprintf(temp,"kuti %s",output);
				strcpy(output,temp);
			}
		}
		sscanf(input,"%lu",&n);
		recursive(n,term,output);
		if(strcmp(output,"")==0)
			printf("0\n");
		else
			printf("%s\n",output);

	}
    return 0;
}
Esempio n. 3
0
int			recursive(t_map *map, t_trimino *tetrimino)
{
	int	newpos;

	if (protect_stack(map, tetrimino))
		return (1);
	newpos = find_next_pos(map, tetrimino);
	if (newpos)
	{
		if (newpos <= map->target)
		{
			if (tetrimino->next)
				return (recursive(map, tetrimino->next));
		}
		else
			return (recursive(map, tetrimino));
	}
	else if (tetrimino->prev)
	{
		map_unprint_tetrimino(map, tetrimino);
		return (recursive(map, tetrimino->prev));
	}
	else if (!tetrimino->prev)
		return (1);
	return (0);
}
Esempio n. 4
0
struct ListNode *recursive(struct ListNode *head, int n)
{
    if (head == NULL || head->next == NULL)
    {
        return head;
    }
    
    int mid = (n-1) / 2;
    int i = 0;
    struct ListNode *pLeft = head;
    struct ListNode *pRight = NULL;
    struct ListNode *pNode = head;
    
    //分开两部分
    for (i = 0; i < mid; i++)
    {
        pNode = pNode->next;
    }
    pRight = pNode->next;
    pNode->next = NULL;
    
    pLeft = recursive(pLeft, mid+1);
    pRight = recursive(pRight, n-mid-1);
    
    head = Merge(pLeft, pRight);
    
    return head;
}
Esempio n. 5
0
void
CollectionSetup::writeConfig()
{
    //If we are in recursive mode then we don't need to store the names of the
    //subdirectories of the selected directories
    if ( recursive() )
    {
        for ( QStringList::iterator it=m_dirs.begin(); it!=m_dirs.end(); ++it )
        {
            QStringList::iterator jt=m_dirs.begin();
            while ( jt!=m_dirs.end() )
            {
                if ( it==jt )
                {
                    ++jt;
                    continue;
                }
                //Note: all directories except "/" lack a trailing '/'.
                //If (*jt) is a subdirectory of (*it) it is redundant.
                //As all directories are subdirectories of "/", if "/" is selected, we
                //can delete everything else.
                if ( ( *jt ).startsWith( *it + '/' ) || *it=="/" )
                    jt = m_dirs.remove( jt );
                else
                    ++jt;
            }
        }
    }

    AmarokConfig::setCollectionFolders( m_dirs );
    AmarokConfig::setScanRecursively( recursive() );
    AmarokConfig::setMonitorChanges( monitor() );
}
Esempio n. 6
0
//fib(n-1)+fib(n-2) = next_sum
//0,1,1,2,3,5,8,13.....,end of 46,47 will be overflow
int recursive(int num){
    
    int tempsum = 0;
        if(num<=0){return(0);}
        else if(num==1){return(1);}        
       return( recursive(num-1)+recursive(num-2)); 
      
    }
Esempio n. 7
0
 /** \brief calculates the n-th Fibonacci number by using naive recursion
  *
  * \param n the zero-based index of the desired Fibonacci number
  * \return Returns the n-th Fibonacci number.
  */
 static intT recursive(unsigned int n)
 {
   if (n == 0)
     return f0;
   if (n == 1)
     return f1;
   return recursive(n-1)+recursive(n-2);
 }
 void recursive(int left,int right,string s,vector<string> &v){
     if(left == 0 && right == 0){
         v.push_back(s);
         return ;
     }
     if(left > 0){
         recursive(left-1,right,s+'(',v);
     }
     if(right > 0 && right > left){
         recursive(left,right-1,s+')',v);
     }
 }
Esempio n. 9
0
int main(int argc, char* argv[])
{
	std::cout << "Test" << std::endl ;

	recursive(0) ;

	func5() ;

	recursive(10) ;

	return 0 ;
}
 int strobogrammaticInRange(string low, string high) {
     int len_low = low.length();
     int len_high = high.length();
     int total = 0;
     if (len_low == 0 || len_high == 0) return 0;
     vector<char> nums1 = {'0', '1', '6', '8', '9'};
     vector<char> nums2 = {'0', '1', '9', '8', '6'};
     recursive("", nums1, nums2, low, high, total);
     recursive("0", nums1, nums2, low, high, total);
     recursive("1", nums1, nums2, low, high, total);
     recursive("8", nums1, nums2, low, high, total);
     return total;
 }
node *recursive(node *curr1,node *curr2,int prev){
	if(NULL==curr1 || NULL==curr2)
		return NULL;
	if(curr1->data<curr2->data)
		return recursive(curr1->next,curr2,prev);
	if(curr2->data<curr1->data)
		return recursive(curr1,curr2->next,prev);
	if(prev!=curr1->data){
		node *temp=createNewNode(curr1->data);
		temp->next=recursive(curr1->next,curr2->next,temp->data);
		return temp;
	}else
		return recursive(curr1->next,curr2->next,prev);
}
Esempio n. 12
0
long long recursive(long long d, long long current, long long increment)
{
	if(((d-current) - (current*current)) < 0)
	{
		if( (d-current+1) - ((current-1) * (current-1)) >=0)
			return current-1;
		else
			return recursive(d, current-(increment/2), 1);
	}
	else
	{
		return recursive(d, current + increment, increment*increment);
	}
}
Esempio n. 13
0
void DOMTreeView::recursive(const DOM::Node &pNode, const DOM::Node &node)
{
    QListViewItem *cur_item;
    if(pNode.ownerDocument() != document)
    {
	QString val = node.nodeValue().string();
	if ( val.length() > 20 )
	    val.truncate( 20 );
	cur_item = new QListViewItem(static_cast<QListView *>(this), node.nodeName().string(), val );
	document = pNode.ownerDocument();
    }
    else {
	QString val = node.nodeValue().string();
	if ( val.length() > 20 )
	    val.truncate( 20 );
	cur_item = new QListViewItem(m_itemdict[pNode.handle()], node.nodeName().string(), val);
    }

    if(node.handle())
    {
	m_itemdict.insert(node.handle(), cur_item);
	m_nodedict.insert(cur_item, new DOM::Node(node));
    }

    DOM::Node cur_child = node.lastChild();
    while(!cur_child.isNull())
    {
	recursive(node, cur_child);
	cur_child = cur_child.previousSibling();
    }
}
Esempio n. 14
0
uint64_t recursive(uint64_t n)
{
    if (n < 2) {
        return 1;
    }
    return n * recursive(n - 1);
}
Esempio n. 15
0
int main()
{
	int total, couple;
	int num1, num2;
	int i;
	int value = 1;
	int result = 0;
	//memset(student, 0, sizeof(student));
	//memset(visited,0,sizeof(visited));
	
	scanf("%d %d", &total, &couple);

	for(int i=0; i<couple; i++){
		scanf("%d %d",&num1,&num2);
		create_node(num1,num2);
	}

	
	for(i=1; i<total+1; i++){
		if( recursive(i,value) )
			value++;
	}

	for(i=1; i<total+1; i++){
		if(visited[i] == 0)
			result++;
	}

	printf("%d\n",result+value-1);
	return 0;
}
int RecursiveTest::recursive(int a) {
    if (a == 1) {
        return 1;
    }

    return a * recursive(a - 1);
}
 int recursive(vector<int> A, vector<int> B, int target, int index, vector<vector<int> >& map){
     //cout<<index<<endl;
     if(index>= A.size())
         return 0;
         
     int diff;
     int minVal=INT_MAX;
     
     for(int i=1;i<100;i++){
         
         if(index!=0 ){
             if(abs(i-B[index-1])>target)
                 continue;
         }
         
         B[index]=i;
         
         if (map[index][i - 1] != INT_MAX) {
             diff = map[index][i - 1];
             minVal = min(diff,minVal);
             continue;
         }
         
         diff = abs(i-A[index]);
         diff += recursive(A,B,target,index+1, map);
         
         minVal = min(diff,minVal);
         map[index][i - 1] = diff;
         
         B[index] = A[index];
         
     }
     
     return minVal;
 }
 void recursive(string temp, vector<char> &nums1, vector<char> &nums2, string &low, string &high, int &total) {
     int len = temp.length();
     if (len > low.length() && len < high.length()) {
         if (len > 1 && temp[0] != '0') total++;
     }
     else if (len == low.length() && len < high.length()) {
         if (compareString(low, temp)) {
             if (len > 1 && temp[0] == '0');
             else total++;
         }
     }
     else if (len == high.length() && len > low.length()) {
         if (compareString(temp, high)) {
             if (len > 1 && temp[0] == '0');
             else total++;
         }
     }
     else if (len > high.length()) {
         return;
     }
     else if (len == low.length() && len == high.length()) {
         if (compareString(temp, high) && compareString(low, temp)) {
             if (len > 1 && temp[0] == '0');
             else total++;
         }
     }
     for (int i = 0; i < nums1.size(); ++i) {
         recursive(nums1[i] + temp + nums2[i], nums1, nums2, low, high, total);
     }
 }
Esempio n. 19
0
int recursive (source *src, order *ord, int *p, int *res, int j, int cur, int n){
  //if (j >= n) return 1;
  int i;
  for (i = j; i<n; i++){
    /*int s=0;
      for (s=0; s<n;s++)
      printf("_%d %d\n", res[s], p[i]);*/
      
    if (iscorrect (src, ord, n-1, res, p[i])){
       if (cur > max)
       max = cur;
      res[cur] = p[i];
      
      d = (int**) realloc(d, (size+1)*sizeof(int*));
      d[size] = (int*) malloc(n*sizeof(int));
      memcpy(d[size], res, n*sizeof(int));
      size++;
      
      if (recursive (src, ord, p, res, i+1, cur+1, n)) return 1;
      res[cur] = 0; //backtrace
    }
    //printf("=========\n");
  }

  return 0;
}
Esempio n. 20
0
 Lock::GlobalWrite::GlobalWrite(bool sg) : stopGreed(sg), old(threadState()) {
     if( old == 'W' ) { 
         recursive()++;
         DEV if( stopGreed ) { 
             log() << "info Lock::GlobalWrite does not stop greed on recursive invocation" << endl;
         }
     }
Esempio n. 21
0
void recursive(int i)
{
    if(i<20)
        recursive(++i) ;

	new char[i] ;
}
Esempio n. 22
0
void Parser::parseToConsole()
{

    dirFilters();

#ifdef Q_OS_LINUX
    if(!itsDir->exists(itsArgv[1]))
#else
    if(!itsDir->exists(QString::fromLocal8Bit(itsArgv[1])))
#endif
    {
        qCritical() << "EROR: path to list don't exist\n";
        return;
    }

    QTextStream itsOut(stdout);

#ifdef Q_OS_LINUX
    itsDir->cd(itsArgv[1]);
    itsOut << "ROOT DIR:\n" << QDir::toNativeSeparators(itsArgv[1]) << ":\n";
#else
    itsDir->cd(QString::fromLocal8Bit(itsArgv[1]));
    itsOut << "ROOT DIR:\n" << QDir::toNativeSeparators(QString::fromLocal8Bit(itsArgv[1])) << ":\n";
    itsOut.flush(); // чтобы ROOT DIR выводился в начале, а не в конце
#endif

    if(itsOptions.testFlag(RECURSIVE))
    {
        recursive(itsDir->absolutePath());
    }
    else
    {
        notRecursive(itsDir->absolutePath());
    }
}
Esempio n. 23
0
int recursive(int StartNumber, int Difference, int N) {
	if(N == 0) {
		return 0;
	} else {
		return (StartNumber + recursive((StartNumber+Difference),Difference,(N-1)));
	}    
}
Esempio n. 24
0
void Parser::recursive(const QString &dirPath, QTextStream &out)
{
    wait();
    itsDir->cd(dirPath);

    QFileInfoList list = itsDir->entryInfoList();

    for(int iList = 0; iList < list.size(); ++iList)
    {
        QFileInfo fileInfo = list.at(iList);
        QString filePath = fileInfo.absoluteFilePath();

        if(fileInfo.isDir())
        {
            if(itsOptions.testFlag(SHOWDIRS))
            {
                if(itsOptions.testFlag(ABSOLUTEPATH))
                {
                    out << "\nSUBDIR:\n" << QDir::toNativeSeparators(filePath) << ":" << "\n";
                }
                else
                {
                    QString temp = filePath;
                    out << "\nSUBDIR:\n.." << QDir::toNativeSeparators(temp.remove(0, QString(itsArgv[1]).size())) << ":\n";
                }
            }
            recursive(filePath, out);
        }
        else
        {
            out << fileInfo.fileName() << "\n";
        }
    }
}
 int recursive(vector<int> A, vector<int> B, int target, int index){
     //cout<<index<<endl;
     if(index>= A.size())
         return 0;
         
     int diff;
     int minVal=INT_MAX;
     
     for(int i=0;i<100;i++){
         
         if(index!=0 ){
             if(abs(i-B[index-1])>target)
                 continue;
         }
         
         B[index]=i;
         
         diff = abs(i-A[index]);
         diff += recursive(A,B,target,index+1);
         
         minVal = min(diff,minVal);
         
         B[index] = A[index];
         
     }
     
     return minVal;
 }
int main(){
	node *head1,*head2;
	int n;
	
	head1=NULL;
	head1=createNewNode(11);
	head1->next=createNewNode(11);
	head1->next->next=createNewNode(12);
	head1->next->next->next=createNewNode(12);
	head1->next->next->next->next=createNewNode(16);
	head1->next->next->next->next->next=createNewNode(17);
	
	head2=NULL;
	head2=createNewNode(11);
	head2->next=createNewNode(12);
	head2->next->next=createNewNode(12);
	head2->next->next->next=createNewNode(14);
	head2->next->next->next->next=createNewNode(16);
	head2->next->next->next->next->next=createNewNode(19);
	
	printf("\nLinked lists are:\n");
	printList(head1);
	printf("\n");
	printList(head2);
	node *head=recursive(head1,head2,-1);
	printf("\nLinked list is:");
	printList(head);
	printf("\n");
	return 0;
}
void KMSearch::start()
{
  //close all referenced folders
  QList<QPointer<KMFolder> >::Iterator fit;
  for ( fit = mOpenedFolders.begin(); fit != mOpenedFolders.end(); ++fit ) {
    if ( !(*fit) ) {
      continue;
    }
    (*fit)->close( "kmsearch" );
  }
  mOpenedFolders.clear();
  mFolders.clear();

  if ( running() ) {
    return;
  }

  if ( !mSearchPattern ) {
    emit finished( true );
    return;
  }

  mFoundCount = 0;
  mSearchCount = 0;
  mRunning = true;

  mFolders.append( mRoot );
  if ( recursive() ) {
    //Append all descendants to folders
    KMFolder *folder;
    for ( int i = 0; i < mFolders.size(); i++ ) {
      folder = mFolders[i];
      KMFolderDir *dir = 0;
      if ( folder ) {
        dir = folder->child();
      } else {
        dir = &kmkernel->folderMgr()->dir();
      }
      if ( !dir ) {
        continue;
      }

      QListIterator<KMFolderNode*> it( *dir );
      while ( it.hasNext() ) {
        KMFolderNode *node = it.next();
        if ( !node->isDir() ) {
          KMFolder* kmf = dynamic_cast<KMFolder*>( node );
          if ( kmf ) {
            mFolders.append( kmf );
          }
        }
      }
    }
  }

  mRemainingFolders = mFolders.count();
  mLastFolder.clear();
  mProcessNextBatchTimer->start( 0 );
}
Esempio n. 28
0
void recursive (int num)
{
    if (num <= 0)
        return;
    printf("Recursive call %d \n", num);
    recursive (num-1);
    printf("i got out late for the %dth time\n", num);
}
Esempio n. 29
0
void DOMTreeView::showTree(const DOM::Node &pNode)
{
    if(pNode.isNull() || document != pNode.ownerDocument())
    {
	clear();
	m_itemdict.clear();
	m_nodedict.clear();
	if(pNode.isNull())
	    return;
	else if(pNode.ownerDocument().isNull())
	    recursive(0, pNode);
	else
	    recursive(0, pNode.ownerDocument());
    }
    setCurrentItem(m_itemdict[pNode.handle()]);
    ensureItemVisible(m_itemdict[pNode.handle()]);
}
Esempio n. 30
0
void
CollectionSetup::writeConfig()
{
    AmarokConfig::setCollectionFolders( m_dirs );
    AmarokConfig::setScanRecursively( recursive() );
    AmarokConfig::setMonitorChanges( monitor() );
    AmarokConfig::setImportPlaylists( importPlaylists() );
}