试图分析
  • 板块P1229 遍历问题
  • 楼主JK01WYX
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/11/19 22:52
  • 上次更新2023/11/20 00:43:44
查看原帖
试图分析
798434
JK01WYX楼主2023/11/19 22:52

前序abc:

a肯定是根b可以是a的左右子树

如果b是a的左子树,那么c可以是b的左右子树,(还可以是a的右子树!但是后序就变了)

如果b是a的右子树,那么c可以是b的左右子树

后序cba:

a肯定是根

如果c是左子树,不符合同一棵树了(->acb)

那么bc只能是父子关系!

所以,经分析,只有这样父子关系的一棵树前序和后序才会如题

而前序和后序的这种情况两个节点是挨着的(方向不一样而已),遇见了乘以2

#define _CRT_SECURE_NO_WARNINGS 1
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
using namespace std;
#include <unordered_map>
#include <vector>
#include <math.h> 
#include <list> 
#include <map> 
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <string>
#include <algorithm>//sort
#include <stdlib.h>
#include <iomanip>
#include <cstring>//memset
#include <limits.h>
/*ios::sync_with_stdio(false);
cin.tie(0);*/

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //
    string a,b;
    cin >> a >> b;
    int n = a.size();
    int ans = 1;
    for (int i = 0; i < n-1; i++)
    {
        for (int j = 1; j < n; j++)
        {
            if (a[i] == b[j] && a[i + 1] == b[j - 1])
                ans *= 2;
        }
    }
    cout << ans;
    return 0;
}
2023/11/19 22:52
加载中...