http://ac.jobdu.com/problem.php?pid=1009
来源:互联网 发布:套筒扳手 淘宝 编辑:程序博客网 时间:2024/04/30 05:18
- 题目描述:
- 判断两序列是否为同一二叉搜索树序列
- 输入:
- 开始一个数n,(1<=n<=20) 表示有n个需要判断,n= 0 的时候输入结束。
接下去一行是一个序列,序列长度小于10,包含(0~9)的数字,没有重复数字,根据这个序列可以构造出一颗二叉搜索树。
接下去的n行有n个序列,每个序列格式跟第一个序列一样,请判断这两个序列是否能组成同一颗二叉搜索树。
- 输出:
如果序列相同则输出YES,否则输出NO
- 样例输入:
25674325432675763420
- 样例输出:
YESNO
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <memory.h>
- #include <cstdio>
- #include <cstdlib>
- #include <vector>
- #define MAX 1000000
- using namespace std;
- int a[MAX];
- int b[MAX];
- void insert(int *a, int i, int x){
- if(a[i]==-1){
- a[i] = x;
- return;
- }
- if(x>a[i])
- insert(a, 2*i+1, x);
- else
- insert(a, 2*i, x);
- }
- void clear(int* arr){
- for(int i=0;i<MAX;++i)
- arr[i] = -1;
- }
- int main(){
- //freopen("in.txt", "r", stdin);
- int n;
- string str;
- while(cin>>n, n){
- cin>>str;
- clear(a);
- for(int i=0;i<str.length();++i){
- insert(a, 1, str[i]);
- }
- for(int i=0;i<n;++i){
- clear(b);
- cin>>str;
- for(int j=0;j<str.length();++j)
- insert(b, 1, str[j]);
- bool flag = true;
- for(int k=0;k<MAX;++k){
- if(a[k]==-1 && b[k]!=-1 || a[k]!=-1 && b[k]==-1){
- flag = false;
- break;
- }
- }
- if(flag){
- printf("YES\n");
- }else
- printf("NO\n");
- }
- }
- //fclose(stdin);
- }
- http://ac.jobdu.com/problem.php?pid=1009
- http://ac.jobdu.com/problem.php?pid=1008
- http://ac.jobdu.com/problem.php?pid=1007
- http://ac.jobdu.com/problem.php?pid=1033
- http://ac.jobdu.com/problem.php?pid=1005
- http://ac.jobdu.com/problem.php?pid=1006
- http://ac.jobdu.com/problem.php?pid=1003
- http://ac.jobdu.com/problem.php?pid=1035
- http://ac.jobdu.com/problem.php?pid=1032
- http://ac.jobdu.com/problem.php?pid=1030
- http://ac.jobdu.com/problem.php?pid=1029
- http://ac.jobdu.com/problem.php?pid=1028
- http://ac.jobdu.com/problem.php?pid=1027
- http://ac.jobdu.com/problem.php?pid=1026
- http://ac.jobdu.com/problem.php?pid=1025
- http://ac.jobdu.com/problem.php?pid=1024
- http://ac.jobdu.com/problem.php?pid=1023
- http://ac.jobdu.com/problem.php?pid=1022
- linux信号量编程
- 编写一个简单的 jQuery 插件(模板)
- http://ac.jobdu.com/problem.php?pid=1008
- 连接路由器上面的服务,必须先查看服务是在什么端口上面监听的 ,然后让防火墙开放端口,客户端才可以访问。
- 关于SMALI语法
- http://ac.jobdu.com/problem.php?pid=1009
- linux time相关函数
- exception: AbstractUserDetailsAuthenticationProvider.badCredentials
- 摄氏度化为华氏度
- http://ac.jobdu.com/problem.php?pid=1007
- android中listview的一些样式设置
- http://ac.jobdu.com/problem.php?pid=1033
- 起码我们曾经爱过,不是吗
- 如何创建一个子进程并分离出去运行