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 分)
二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值:它的左.右子树也分别 ...
随机推荐
- ThreadPoolExecutor原理和使用
大家先从ThreadPoolExecutor的整体流程入手: 针对ThreadPoolExecutor代码.我们来看下execute方法: public void execute(Runnable c ...
- 在 DEBIAN 上安装 SQL SERVER
微软在开源 .NET Framework 之后,相继推出了跨平台的编辑器 Visual Studio Code,跨平台的 SQL Server 数据库 SQL Server vNext,Visual ...
- js 动态生成div显示id
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- WPF 数据模板使用值转换器
<Window x:Class="CollectionBinding.MainWindow" xmlns="http://schemas.micros ...
- Marker
# 样例 <?xml version="1.0" encoding="UTF-8"?> <Configuration status=" ...
- QEventLoop的全部源码也不多,混个脸熟
/**************************************************************************** ** ** Copyright (C) 20 ...
- Image Captioning代码复现
Image caption generation: https://github.com/eladhoffer/captionGen Simple encoder-decoder image capt ...
- Win8 Metro(C#)数字图像处理--2.71Sigma平滑滤波器
原文:Win8 Metro(C#)数字图像处理--2.71Sigma平滑滤波器 [算法说明] Sigma平滑滤波器是构造一个模板,比如3*3大小的模板,计算这个模板对应的像素的标准差d,然后 ...
- Oracle报错:不是GROUP BY 表达式
报错:不是GROUP BY 表达式 实例:select sum(hwjz),rq from JcChargeInfo where 1=1 group by rq order by jcchargec ...
- UWP开发学习笔记2
RelativePanel控件: 用法 描述 RelativePanel.Above 设置当前element为目标element的上方 RelativePanel.AlignBottomWith 设置 ...