2265专题

[leetcode]2265. Count Nodes Equal to Average of Subtree

问题入口 时间复杂度:O(n),空间复杂度:O(h) class Solution {public:int count = 0;pair<int, int> postOder(TreeNode* root){if (!root)return {0, 0};pair<int, int> left = postOder(root->left);pair<int, int> right = pos

POJ 2265 Bee Maja G++ 找规律 巧妙 背

#include <iostream>#include <cstdio>using namespace std;//英语 看博友分析 抄博友程序 找规律 巧妙 背 int main(){int a;while(cin>>a){if(a==1){cout<<0<<" "<<0<<endl;continue;}int n=0;/

POJ 2265 Bee Maja (找规律)

题目链接 题意 : 给你两个蜂巢的编号,给你一个的编号让你输出在另外一个蜂巢中对应的编号。 思路 : 先将蜂巢分层,第一层一个数,第二层6个数,第三层12个数…………然后用公式表示出第n层的最后一个数是多少,下图中竖着的是x坐标,斜着的是y坐标,往左横坐标+1,往右横坐标-1,以斜线为准往上纵坐标-1,往下纵坐标+1,(1,1)也就是18是第三圈的第一个数,(2,1)也就是20是第四圈的第一个数