codeup 二叉树(dfs超时版)

 牛客上也发现了这道题 我的代码竟然过了 看了一下讨论区 好几个人都是dfs的思想 所以其实codeup要求的是更优的一种做法。下篇博客再来写吧。

/**********************
author: yomi
date: 18.8.15
ps:这是需要剪枝的节奏?开玩笑 可没法剪
**********************/
#include <iostream>
using namespace std;
int cnt, m, n;
void dfs(int index, int n)
{
    if(index > n)
        return;
    cnt++;
    dfs(2*index, n);
    dfs(2*index+1, n);
}
int main()
{
    while(cin >> m >> n && m && n){
        cnt = 0;
        dfs(m, n);
        cout << cnt << endl;
    }
    return 0;
}

/**
3 7
142 6574
2 754
0 0

3
63
498
**/
原文地址:https://www.cnblogs.com/AbsolutelyPerfect/p/9480690.html