当前位置: 首页 > news >正文

手做网站涟水建设银行网站

手做网站,涟水建设银行网站,wordpress 手机端页面,浙江网站建设哪家好1判断完全二叉树递归做法 有四种情况#xff1a;1 左树完全#xff0c;右数满#xff0c;且左高为右高加一 2左满 #xff0c;右满#xff0c;左高为右高加一 3左满#xff0c;右完全#xff0c;左右高相等 4左右均满且高相等 #includeiostream #include1 左树完全右数满且左高为右高加一 2左满 右满左高为右高加一 3左满右完全左右高相等 4左右均满且高相等 #includeiostream #includealgorithm using namespace std; class TreeNode { public:int val;TreeNode* left;TreeNode* right;TreeNode(int a) :val(a), left(nullptr), right(nullptr) {}; }; struct info {int height;bool iscbt;bool isfull;info(int a,bool b,bool c):height(a),iscbt(b),isfull(c){} }; info process(TreeNode* head) {if (head nullptr)return info(0, true, true);info leftinfo process(head-left);info rightinfo process(head-right);int height max(leftinfo.height, rightinfo.height) 1;bool isfull leftinfo.isfull rightinfo.isfull leftinfo.height rightinfo.height;bool iscbt false;if (leftinfo.isfull rightinfo.isfull leftinfo.height - rightinfo.height 1)iscbt true;if (leftinfo.isfull rightinfo.isfull leftinfo.height rightinfo.height )iscbt true;if (leftinfo.iscbt rightinfo.isfull leftinfo.height - rightinfo.height 1)iscbt true;if (leftinfo.isfull rightinfo.iscbt leftinfo.height rightinfo.height)iscbt true;return info(height, iscbt, isfull); } bool iscbt(TreeNode* head) {if (head nullptr)return true;return process(head).iscbt; } 2 给定一棵二叉树的头节点head返回这颗二叉树中最大的二叉搜索子树的头节点 #include iostream #include vector #include algorithm using namespace std; class TreeNode { public:int val;TreeNode* left;TreeNode* right;TreeNode(int data) : val(data), left(nullptr), right(nullptr) {} }; struct info {TreeNode* node;//最大搜索子树头结点int maxsize;int min;int max;info(TreeNode *a,int b,int c,int d):node(a),maxsize(b),min(c),max(d){} }; info* process(TreeNode* head) {if (head nullptr)return nullptr;info* leftinfo process(head-left);info* rightinfo process(head-right);int maxval head-val;int minval head-val;TreeNode* ans nullptr;int size 0;if (leftinfo ! nullptr){maxval max(maxval, leftinfo-max);minval min(minval, leftinfo-min);ans leftinfo-node;size leftinfo-maxsize;}if (rightinfo ! nullptr){maxval max(maxval, rightinfo-max);minval min(minval, rightinfo-min);if (rightinfo-maxsize size){ans rightinfo-node;size rightinfo-maxsize;}}//当能构成搜索二叉树时if((leftinfonullptr?true:(leftinfo-nodehead-leftleftinfo-maxhead-val)) (rightinfo nullptr ? true : (rightinfo-node head-right rightinfo-min head-val))){anshead;//一定要记得判空size (leftinfo nullptr ? 0 : leftinfo-maxsize) (rightinfo nullptr ? 0 : leftinfo-maxsize) 1;}return new info(ans, size, minval, maxval); } TreeNode* maxSubBSTHead2(TreeNode* head) {if (head nullptr)return nullptr;return process(head)-node; }3给定一棵二叉树的头节点head和另外两个节点a和b返回a和b的最低公共祖先 法1用哈希表记下所有节点父节点将一个节点不停地向上这其中经过的节点放入一个集合中 再在另一个节点从上遍历一遍查找是否在集合中已经存在过找到的第一个即为答案 #include iostream #include unordered_map #include unordered_set using namespace std; class TreeNode { public:int val;TreeNode* left;TreeNode* right;TreeNode(int data) : val(data), left(nullptr), right(nullptr) {} }; void fillmap(TreeNode* head, unordered_mapTreeNode*, TreeNode* map) {if (head-left ! nullptr){map[head-left] head;fillmap(head-left, map);}if (head-right ! nullptr){map[head-right] head;fillmap(head-right, map);} } TreeNode* lowestAncestor(TreeNode* head, TreeNode* p, TreeNode* q) {if (head nullptr)return nullptr;unordered_mapTreeNode*, TreeNode* map;//记录所有节点的父节点map[head] nullptr;fillmap(head,map);unordered_setTreeNode* set;TreeNode* cur p;set.insert(cur);while (map[cur] ! nullptr){cur map[cur];set.insert(cur);}cur q;while (set.find(cur) set.end()){cur map[cur];}return cur; } 法二递归套路会聚点与x有关还是无关无关已经在左或右树右答案或这棵树a,b没找全 x是答案左发现一个右发现一个 x本身就是a然后左右发现了b   x本身就是b左右发现a #include iostream using namespace std;// 节点类 class Node { public:int value;Node* left;Node* right;Node(int data) : value(data), left(nullptr), right(nullptr) {} }; // 最低公共祖先函数 Node* lowestAncestor2(Node* head, Node* a, Node* b) {return process(head, a, b).ans; }// 信息结构体 struct Info {bool findA;bool findB;Node* ans;Info(bool fA, bool fB, Node* an) : findA(fA), findB(fB), ans(an) {} };// 处理函数 Info process(Node* x, Node* a, Node* b) {if (x nullptr) {return Info(false, false, nullptr);}Info leftInfo process(x-left, a, b);Info rightInfo process(x-right, a, b);bool findA (x a) || leftInfo.findA || rightInfo.findA;//不要忘了x本身就是a的情况bool findB (x b) || leftInfo.findB || rightInfo.findB;Node* ans nullptr;if (leftInfo.ans ! nullptr) {ans leftInfo.ans;}else if (rightInfo.ans ! nullptr) {ans rightInfo.ans;}else {if (findA findB) {ans x;}}return Info(findA, findB, ans); }4  派对的最大快乐值  员工信息的定义如下: class Employee {     public int happy; // 这名员工可以带来的快乐值     ListEmployee subordinates; // 这名员工有哪些直接下级 } 公司的每个员工都符合 Employee 类的描述。整个公司的人员结构可以看作是一棵标准的、 没有环的多叉树 树的头节点是公司唯一的老板除老板之外的每个员工都有唯一的直接上级 叶节点是没有任何下属的基层员工(subordinates列表为空)除基层员工外每个员工都有一个或多个直接下级 这个公司现在要办party你可以决定哪些员工来哪些员工不来规则 1.如果某个员工来了那么这个员工的所有直接下级都不能来 2.派对的整体快乐值是所有到场员工快乐值的累加 3.你的目标是让派对的整体快乐值尽量大 给定一棵多叉树的头节点boss请返回派对的最大快乐值。 分情况:x来,x不来定义一个结构体保存两个值x来时候的最大值x不来时候的最大值 #includeiostream #includealgorithm #includevector using namespace std; struct employee {int happy;vectoremployee* nexts;employee(int h):happy(h),nexts(){} }; struct info {int yes;int no;info(int a,int b):yes(a),no(b){} }; info process(employee* head) {if (head nullptr)return info(0, 0);int yes head-happy;int no 0;for (employee* a : head-nexts){info nextinfo process(a);yes nextinfo.no;no max(nextinfo.yes, nextinfo.no);}return info(yes, no); } int maxhappy(employee* head) {info allinfo process(head);return max(allinfo.no, allinfo.yes); } 5给定一个由字符串组成的数组strs必须把所有的字符串拼接起来返回所有可能的拼接结果中字典序最小的结果 贪心局部最小得全体最优解有时候可能会有错 字典序字符串排大小长度一样比数字大小 长度不同较短的补上最小的阿斯克码值然后与长的比较 证明过程得先证明排序过程具有传递性 像石头剪刀布就没有传递性 #include iostream #include vector #include algorithm using namespace std; class compare { public:bool operator()(string a, string b){return (a b) (b a);} }; string lowestString(vectorstring str) {if (str.empty())return ;sort(str.begin(), str.end(), compare());string a;for (string c : str){a c;}return a; }
http://www.zqtcl.cn/news/604925/

相关文章:

  • seo网站优化系统搜索引擎优化排名案例
  • 郑州网站建设工作室网站建设全流程 知乎
  • 如何利用源码做网站外贸网站制作推广
  • 国内做网站哪家公司好免费查找资料的网站
  • 自己做的网站百度搜不到搭建网站seo
  • 奇墙网站建设高端网站建设公司联系电话
  • 宁波那家公司做网站好中企动力科技股份有限公司招聘
  • 水果网站推广网站首页静态好还是动态好
  • iis网站属性小程序源码无需服务器
  • 景区网站建设材料代运营有哪些套路坑
  • 六安电商网站建设哪家好有关做美食的网站
  • 卸载wordpress插件网店seo关键词
  • 金山网站制作赤城seo网站优化排名
  • 提供坪山网站建设深圳商城网站哪家做的好
  • 有什么网站可以帮人做模具吗热搜榜百度一下你就知道
  • 深圳网站优化技巧邹城住房城乡建设部网站
  • 小型企业网站建站桂林市中考信息网官网
  • 雏鸟app网站推广做网站用宋体有版权问题吗
  • 建立网站数据库开公司流程及费用2022最新
  • 外贸谷歌网站推广wordpress调用上传图片
  • 360提示危险网站原因威海 网站开发
  • 赣州本地网站网站怎么写
  • 物业公司网站设计湛江做网站软件
  • 做招聘求职网站wordpress启用插件出错
  • 珠海网站运营网站个人备案流程
  • 网站开发用什么图片格式最好网络营销名词解释是什么
  • 做柜子网站老电脑做网站服务器
  • 域名购买网站网店装修是什么
  • wordpress 网站备份为什么企业要建设自己的企业文化
  • 想做一个部门的网站怎么做潍坊网站建设价