/* 2020/4/16 二刷 */
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
using namespace std;int N;
int input[100][4];
int maxNum = 0;
int maxHeight = 0;
typedef struct node
{
int id;int height;int numChild;node* lchild;node* mchild;node* rchild;
}Node,*Tree;int max(int a,int b)
{
if(a>b) return a;else return b;
}Node* newNode(int id)
{
Node* temp = (Node*)malloc(sizeof(Node));temp->id = id;temp->height = 0;temp->numChild = 0;temp->lchild = NULL;temp->mchild = NULL;temp->rchild = NULL;return temp;
}void createTree(Node* root)
{
int i = 0;int numChild = 0;for(i = 0;i<N;i++){
if(root->id == input[i][0]){
break;}}if(i == N) return;if(input[i][1]){
numChild++;Node* temp1 = newNode(input[i][1]);root->lchild = temp1;createTree(temp1);}if(input[i][2]){
numChild++;Node* temp2 = newNode(input[i][2]);root->mchild = temp2;createTree(temp2);}if(input[i][3]){
numChild++;Node* temp3 = newNode(input[i][3]);root->rchild = temp3;createTree(temp3);}root->numChild = numChild;
}int treeHeight(Node* root)
{
int L,M,R,height;if(root){
L = treeHeight(root->lchild);M = treeHeight(root->mchild);R = treeHeight(root->rchild);height = max(L,max(M,R)) + 1;return height;}elsereturn 0;
}void preOrderGetHeight(Node* root)
{
if(root){
root->height = treeHeight(root);preOrderGetHeight(root->lchild);preOrderGetHeight(root->mchild);preOrderGetHeight(root->rchild);}
}vector<Node*> v;
void preOrderGetSequence(Node* root)
{
if(root){
if(root->numChild==maxNum)v.push_back(root);preOrderGetSequence(root->lchild);preOrderGetSequence(root->mchild);preOrderGetSequence(root->rchild);}
}int main()
{
scanf("%d",&N);for(int i = 0;i<N;i++){
int tempNum = 0;scanf("%d%d%d%d",&input[i][0],&input[i][1],&input[i][2],&input[i][3]);if(input[i][1]!=0) tempNum++;if(input[i][2]!=0) tempNum++;if(input[i][3]!=0) tempNum++;if(tempNum>maxNum) maxNum = tempNum;}Node* root = newNode(input[0][0]);createTree(root);preOrderGetHeight(root);preOrderGetSequence(root);int index = -1;for(int i = 0;i<v.size();i++){
if(v[i]->height > maxHeight){
index = i;maxHeight = v[i]->height;}}printf("%d\n",v[index]->id);return 0;
}
详细解决方案
2018-2
热度:125 发布时间:2023-10-14 06:30:20.0
相关解决方案
- 导出的可运行 jar 不包含来自 eclipse 2018-12 和 java 11 的依赖 jar。我们如何解决这个问题?
- IntellIj Idea 2018.1无法使用Maven 3.6下载源
- 在Kali Linux 2018.2中安装Parallels Tools
- 日期转换错误:Can not deserialize value of type java.util.Date from String 2018-10-25 15:58:31
- 2018 noip 备战日志
- 2018 雅礼国庆集训
- 2018 NOIP备战计划
- 2018 浅谈前端面试那些事
- CVE-2018-12613 --- 本地文件包含造成远程代码执行漏洞复现
- kali 2018.1 64位安装shellter问题解决方法
- kali 2018.1安装vmtools
- 【网络流】【贪心】「九省联考 2018」秘密袭击
- 【线段树】「CodePlus 2018 3 月赛」白金元首与克劳德斯
- 【DP】 [COCI2017-2018#3] Dojave
- 【数论】【容斥原理】【EXGCD】COCI? ?2017/2018 Round? ?#3 ? ?Sa?etak
- VisualStudio神级插件——JetBrains Resharper 2018.3.4 Ultimate完美破解版+教程(转载)
- 安装kali Linux 2018.2以后的事
- summary(2018.10.23) 关于推荐系统(数据挖掘)
- 2018-2
- 2018-1
- 2018-09-11 记录生活的美好,记录技术的进步
- win10,安装Anaconda3-2018.12-windows-x86_64
- phpMyAdmin文件包含漏洞复现(CVE-2018-12613)
- 【文献阅读】 2018-SIGKDD-STAMP:Short-Term Attention/Memory Priority Model for Session-based Recommendation
- 【牛客网】2018-03-24广东工业大学ACM程序设计大赛(未)
- 看雪CTF.TSRC 2018 团队赛-第六题 追凶者也--拼图游戏
- 回望(总结)2017,展望(规划)2018
- 2018 蓝桥杯省赛 B 组模拟赛(一)
- ACM-ICPC 2018 南京赛区网络预赛题解
- The 2018 ACM-ICPC Chinese Collegiate Programming Contest题解(计蒜课第五场)