数树数
题目
题目分析
通过图片的二叉树,我们可以发现每一个·分支的
L=2a-1
R=2a
代码
#include <iostream> #include<string> using namespace std; char s[50]; int a; int main() { int n, q; cin >> n >> q; for (int i = 0; i < q; i++) { cin >> s; a = 1; for (int j = 0; j < strlen(s); j++)//每一层分支 { if (s[j] == 'L') { a = 2 * a - 1; } else { a = 2 * a; } } cout << a << endl; } return 0; }
标签:数树数,include,int,cin,蓝桥,例题 From: https://www.cnblogs.com/hcrzhi/p/18427985