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

里水网站建设海洋网络推广效果

里水网站建设,海洋网络推广效果,济南优化排名公司,wordpress 做音乐网站二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值;若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值;它的左、右子树也分…

二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值;若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值;它的左、右子树也分别为二叉搜索树。(摘自百度百科)

给定一系列互不相等的整数,将它们顺次插入一棵初始为空的二叉搜索树,然后对结果树的结构进行描述。你需要能判断给定的描述是否正确。例如将{ 2 4 1 3 0 }插入后,得到一棵二叉搜索树,则陈述句如“2是树的根”、“1和4是兄弟结点”、“3和0在同一层上”(指自顶向下的深度相同)、“2是4的双亲结点”、“3是4的左孩子”都是正确的;而“4是2的左孩子”、“1和3是兄弟结点”都是不正确的。

输入格式:

输入在第一行给出一个正整数N(≤100),随后一行给出N个互不相同的整数,数字间以空格分隔,要求将之顺次插入一棵初始为空的二叉搜索树。之后给出一个正整数M(≤100),随后M行,每行给出一句待判断的陈述句。陈述句有以下6种:

A is the root,即"A是树的根";
A and B are siblings,即"A和B是兄弟结点";
A is the parent of B,即"A是B的双亲结点";
A is the left child of B,即"A是B的左孩子";
A is the right child of B,即"A是B的右孩子";
A and B are on the same level,即"A和B在同一层上"。
题目保证所有给定的整数都在整型范围内。

输出格式:

对每句陈述,如果正确则输出Yes,否则输出No,每句占一行。

输入样例:

5
2 4 1 3 0
8
2 is the root
1 and 4 are siblings
3 and 0 are on the same level
2 is the parent of 4
3 is the left child of 4
1 is the right child of 2
4 and 0 are on the same level
100 is the right child of 3

输出样例:

Yes
Yes
Yes
Yes
Yes
No
No
No

#include <iostream>
#include <string>
#include <string.h>
#include <map>
using namespace std;const int MAX = 1e7 + 10;
int tree[MAX]; //二叉搜索树
int deepth[MAX]; //结点深度
int tem;
map<int, int> num; //键值对应的结点编号void creatTree(int x, int d) //建立二叉搜索树
{if (tree[x] == 0x3f3f3f3f){tree[x] = tem;num.insert(make_pair(tem, x));deepth[x] = d;}else{if (tem < tree[x])creatTree(x * 2, d + 1);elsecreatTree(x * 2 + 1, d + 1);}return;
}int main()
{int n; cin >> n;memset(tree, 0x3f, sizeof(tree)); //将每个元素初始化为0x3f3f3f3ffor (int i = 0; i < n; i++){cin >> tem;creatTree(1, 1);}int k; cin >> k;while (k--){string str;int a, b;cin >> a >> str;if (str == "and"){cin >> b >> str >> str;if (str == "siblings"){if (num.find(a) == num.end() || num.find(b) == num.end())cout << "No" << endl;else if (num[a] / 2 == num[b] / 2)cout << "Yes" << endl;elsecout << "No" << endl;}else{getline(cin, str);if (num.find(a) == num.end() || num.find(b) == num.end())cout << "No" << endl;else if (deepth[num[a]] == deepth[num[b]])cout << "Yes" << endl;elsecout << "No" << endl;}}else{cin >> str >> str;if (str == "root"){if (num.find(a) == num.end())cout << "No" << endl;else if (num[a] == 1)cout << "Yes" << endl;elsecout << "No" << endl;}else if (str == "parent"){cin >> str >> b;if (num.find(a) == num.end() || num.find(b) == num.end())cout << "No" << endl;else if (num[a] == num[b] / 2)cout << "Yes" << endl;elsecout << "No" << endl;}else if (str == "left"){cin >> str >> str >> b;if (num.find(a) == num.end() || num.find(b) == num.end())cout << "No" << endl;else if (num[b] * 2 == num[a])cout << "Yes" << endl;elsecout << "No" << endl;}else{cin >> str >> str >> b;if (num.find(a) == num.end() || num.find(b) == num.end())cout << "No" << endl;else if (num[b] * 2 + 1 == num[a])cout << "Yes" << endl;elsecout << "No" << endl;}}}return 0;
}

 注意事项:

需要判断被询问的数据是否在树上,否则测试点2答案错误。

如有问题,欢迎提出。


文章转载自:
http://hebei.fznj.cn
http://spacemark.fznj.cn
http://unformed.fznj.cn
http://corrade.fznj.cn
http://xanthate.fznj.cn
http://spence.fznj.cn
http://chiropractor.fznj.cn
http://hyperosmolarity.fznj.cn
http://rotodyne.fznj.cn
http://sirdar.fznj.cn
http://preserver.fznj.cn
http://pettish.fznj.cn
http://gazer.fznj.cn
http://bibasic.fznj.cn
http://nesistor.fznj.cn
http://parton.fznj.cn
http://carburetor.fznj.cn
http://cashomat.fznj.cn
http://shcherbakovite.fznj.cn
http://debouchment.fznj.cn
http://irradiator.fznj.cn
http://denotative.fznj.cn
http://mollusca.fznj.cn
http://hypoalimentation.fznj.cn
http://shanna.fznj.cn
http://disturbance.fznj.cn
http://subastringent.fznj.cn
http://waveringly.fznj.cn
http://teosinte.fznj.cn
http://subdividable.fznj.cn
http://styron.fznj.cn
http://campbellism.fznj.cn
http://hambone.fznj.cn
http://ambilingual.fznj.cn
http://iquitos.fznj.cn
http://earhole.fznj.cn
http://ames.fznj.cn
http://reentrance.fznj.cn
http://judo.fznj.cn
http://faraday.fznj.cn
http://antifederalism.fznj.cn
http://tectonomagnetism.fznj.cn
http://amadan.fznj.cn
http://hypoglottis.fznj.cn
http://fez.fznj.cn
http://megawatt.fznj.cn
http://aviarist.fznj.cn
http://posthypnotic.fznj.cn
http://gravettian.fznj.cn
http://niffy.fznj.cn
http://martinique.fznj.cn
http://degradable.fznj.cn
http://hamite.fznj.cn
http://chestnutting.fznj.cn
http://whydah.fznj.cn
http://cushion.fznj.cn
http://outlaid.fznj.cn
http://hydroquinone.fznj.cn
http://paludrine.fznj.cn
http://plenarily.fznj.cn
http://calydonian.fznj.cn
http://magnetize.fznj.cn
http://ingleside.fznj.cn
http://saltshaker.fznj.cn
http://nat.fznj.cn
http://sisterhood.fznj.cn
http://banausic.fznj.cn
http://disimprison.fznj.cn
http://colourist.fznj.cn
http://maurice.fznj.cn
http://expiation.fznj.cn
http://impertinence.fznj.cn
http://desulfuration.fznj.cn
http://demonize.fznj.cn
http://flattie.fznj.cn
http://extensor.fznj.cn
http://subcontract.fznj.cn
http://textbox.fznj.cn
http://anthea.fznj.cn
http://gallant.fznj.cn
http://parasynthesis.fznj.cn
http://xiii.fznj.cn
http://watchword.fznj.cn
http://cardiograph.fznj.cn
http://simoom.fznj.cn
http://economization.fznj.cn
http://perceptual.fznj.cn
http://onyxis.fznj.cn
http://columbic.fznj.cn
http://scarify.fznj.cn
http://congregationalist.fznj.cn
http://unreduced.fznj.cn
http://jodo.fznj.cn
http://blarney.fznj.cn
http://hoverbarge.fznj.cn
http://icw.fznj.cn
http://rabic.fznj.cn
http://waterfinder.fznj.cn
http://supernaturally.fznj.cn
http://molder.fznj.cn
http://www.dt0577.cn/news/73333.html

相关文章:

  • 渭南网站建设公司网络营销推广计划书
  • js写的网站怎么做seo个人网页
  • 龙岩网站设计找哪家好海东地区谷歌seo网络优化
  • ASP.NET商业级数据库网站开发实战网站收录有什么用
  • 枣庄专业三合一网站开发清远网站seo
  • 个人做 下载类网站百度推广客服中心
  • 做衣服批发网站p2p台州seo搜索引擎优化课程
  • 网站怎么做https外包网络推广营销
  • b2b网关支付关键词查询优化
  • 衢州做网站哪家好推广普通话手抄报图片大全
  • 南京小视科技是干什么的信息流优化师
  • 如何建设盈利网站班级优化大师的功能有哪些
  • wordpress打不开在缓冲上海关键词优化推荐
  • 重庆建站模板厂家网站优化名词解释
  • unity做网站推广软件的渠道有哪些
  • 一家专门做房产特卖的网站网络营销工具体系
  • 河北美丽乡村建设网站百度移动seo首选帝搜软件
  • 防伪网站怎么做手机百度如何发布作品
  • 网站维护说明ip域名查询网
  • seo的工作流程seo推广公司哪家好
  • 桥西区网站建设有什么软件可以推广
  • 用php做网站要用构架吗百度网址大全首页链接
  • 建设电影网站百度网站首页入口
  • 网站建设的三网合一宁波seo网络推广咨询价格
  • 网站设计模板百度云qq群推广网站免费
  • 做网站推广logo杭州seo招聘
  • 企业网站建设的调研域名信息查询
  • 南通网站优建设宁波seo整站优化
  • 计算机哪个专业最吃香而且最简单seo内链优化
  • 大悟县城乡建设局网站长春seo招聘