PAT L3-016:二叉搜索树的结构(暴力)
https://www.patest.cn/contests/gplt/L3-016
题意:中文。
思路:暴力构造,暴力查询就好了。只不过操作很多,很麻烦。比赛的时候再给我10分钟就打完了,手速太慢好可惜。
#include <bits/stdc++.h>
using namespace std;
#define N 100010
typedef long long LL;
struct Node {
int num;
Node *l, *r, *fa;
Node (int n) {
l = r = fa = NULL;
num = n;
}
} ;
Node *root;
int flag, d;
char s[][]; void Insert(Node *now, Node *f, int x, int kind) {
if(now == NULL) {
now = new Node(x);
now->fa = f;
if(kind) f->r = now;
else f->l = now;
return ;
}
if(x > now->num) Insert(now->r, now, x, );
else Insert(now->l, now, x, );
} Node *Find(int x) {
Node *now = root; d = ;
while(now != NULL && now->num != x) {
if(x > now->num) now = now->r;
else now = now->l;
d++;
}
return now;
} void Solve1(int x) {
if(root && root->num == x) flag = ;
} void Solve2(int x, int y) {
Node *now1 = Find(x), *now2 = Find(y);
if(now1 && now2 && now1->fa == now2->fa) flag = ;
} void Solve3(int x, int y) {
Node *now = Find(y);
if(now && now->fa && now->fa->num == x) flag = ;
} void Solve4(int x, int y) {
Node *now = Find(y);
if(now && now->l && now->l->num == x) flag = ;
} void Solve5(int x, int y) {
Node *now = Find(y);
if(now && now->r && now->r->num == x) flag = ;
} void Solve6(int x, int y) {
Node *now1 = Find(x);
int d1 = d;
Node *now2 = Find(y);
int d2 = d;
if(now1 && now2 && d1 == d2) flag = ;
} int main() {
int n, a, b; scanf("%d", &n);
if(n) scanf("%d", &a), root = new Node(a);
for(int i = ; i < n; i++) scanf("%d", &a), Insert(root, NULL, a, );
int q; scanf("%d", &q);
while(q--) {
flag = ;
scanf("%d", &a);
scanf("%s", s[]);
if(s[][] == 'a') {
scanf("%d", &b);
scanf("%s %s", s[], s[]);
if(s[][] == 's') {
Solve2(a, b);
} else {
Solve6(a, b);
scanf("%s %s %s", s[], s[], s[]);
}
} else {
scanf("%s %s", s[], s[]);
if(s[][] == 'o') {
Solve1(a);
} else if(s[][] == 'a') {
scanf("%s %d", s[], &b), Solve3(a, b);
} else if(s[][] == 'e') {
scanf("%s %s %d", s[], s[], &b), Solve4(a, b);
} else {
scanf("%s %s %d", s[], s[], &b), Solve5(a, b);
}
}
if(flag) puts("Yes");
else puts("No");
}
return ;
}
PAT L3-016:二叉搜索树的结构(暴力)的更多相关文章
- PTA 7-2 二叉搜索树的结构(30 分)
7-2 二叉搜索树的结构(30 分) 二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大 ...
- 二叉搜索树的结构(30 分) PTA 模拟+字符串处理 二叉搜索树的节点插入和非递归遍历
二叉搜索树的结构(30 分) PTA 模拟+字符串处理 二叉搜索树的节点插入和非递归遍历 二叉搜索树的结构(30 分) 二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则 ...
- 二叉搜索树的结构(30 分) PTA 模拟+字符串处理 二叉搜索树的节点插入和非递归遍历
二叉搜索树的结构(30 分) 二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大于它的根 ...
- 【开200数组解决二叉搜索树的建立、遍历】PAT-L3-016. 二叉搜索树的结构——不用链表来搞定二叉搜索树
L3-016. 二叉搜索树的结构 二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大于它 ...
- PAT L3-016 二叉搜索树的结构
https://pintia.cn/problem-sets/994805046380707840/problems/994805047903240192 二叉搜索树或者是一棵空树,或者是具有下列性质 ...
- L3-1 二叉搜索树的结构 (30 分)
讲解的很不错的链接:https://blog.csdn.net/chudongfang2015/article/details/79446477#commentBox 题目链接:https://pin ...
- L3-016 二叉搜索树的结构 (30 分) 二叉树
二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值:它的左.右子树也分别 ...
- L3-016. 二叉搜索树的结构
二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值:它的左.右子树也分别 ...
- L3-016 二叉搜索树的结构 (30 分)
二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值:它的左.右子树也分别 ...
随机推荐
- 获取 UIElement 相对于屏幕原点所占用的矩形区域
原文:获取 UIElement 相对于屏幕原点所占用的矩形区域 <Grid Background="Transparent"> <StackPanel Margi ...
- WPF特效-鱼游动动画2
原文:WPF特效-鱼游动动画2 纯代码撸动画实践2: 原图:(png格式) ...
- net share列出了Windows的默认共享(包括C盘)
另外还有单独开启办法: 开启共享方法: 命令行方式:net share 博客=F:\娱乐\种子 我设置了一个名为“博客”的共享,路径为:“F:\娱乐\种子”. GUI方式:找到“F:\娱乐”的“种子” ...
- 查看window端口占用并结束相关进程
启动cmd命令行 运行netstat –ano,可列出所有端口情况 根据被占用的端口号,比如8081,运行netstat -aon|findstr "8081",找到它对应的PID ...
- Qt 5.9对Mac的图形显示有许多改进
We have some platform specific improvements as well as support for new platforms and compilers comin ...
- ArcGIS for Desktop入门教程_第七章_使用ArcGIS进行空间分析 - ArcGIS知乎-新一代ArcGIS问答社区
原文:ArcGIS for Desktop入门教程_第七章_使用ArcGIS进行空间分析 - ArcGIS知乎-新一代ArcGIS问答社区 1 使用ArcGIS进行空间分析 1.1 GIS分析基础 G ...
- CentOS 7 配置163源
具体的操作步骤: 1.打开终端,输入su指令切换到root用户:su 2.切换到系统yum源的目录下,即:cd /etc/yum.repos.d 3.备份系统默认yum源(也可直接删除):mv Cen ...
- 华为ensp的安装和使用
去年学完了Cisco的路由交换,从CCNA学到CCIE.学完之后才发现,整个国内市场好像更倾向于使用华为.H3C这类国有网络设备厂商.不过还好,至少网络的基础理论知识是相同的,于是买了基本关于HUAW ...
- Tomcat cache 缓存 编译
http://tomcat.apache.org/tomcat-7.0-doc/jasper-howto.html development - Is Jasper used in developmen ...
- 更改当前电源策略(使用SetActivePwrScheme API函数),自定义电源按钮动作(设置GLOBAL_POWER_POLICY)
#include <windows.h> #include <Powrprof.h> #pragma comment(lib, "Powrprof.lib" ...