hdu5444-Elven Postman-最最朴素的二叉搜索树
来源:互联网 发布:新手淘宝买什么摄影棚 编辑:程序博客网 时间:2024/05/29 10:09
就是裸的二叉搜索树
只需要在插入的时候 给节点附加一个W或E的信息
查询时输出该信息就可以
这么水的题居然没看到。。。
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <cstdio>#include <algorithm>#include <iostream>#include <queue>#include <set>#include <vector>#define inf 0x7fffffff#define lson l , m , rt << 1#define rson m + 1 , r , rt << 1 | 1const int maxn = 50005;struct node{int val;node *l,*r;char p;node (){l=r=NULL;}};class Btree{public: void insert(int& sb,node* &hd,int p){if (hd==NULL){hd=new node;hd->val=sb; if (p){if (p==1) hd->p='E';elsehd->p='W';}}else{if (sb<=hd->val)insert(sb,hd->l,1);elseinsert(sb,hd->r,2);}}int query(int& sb,node *hd){if (hd->val==sb){printf("%c",hd->p);return 0;}else{if(hd->p)printf("%c",hd->p); if (sb<=hd->val)query(sb,hd->l);elsequery(sb,hd->r);} }} ;node *head=NULL;Btree tp;int tm[1005];int main(void){int t,n,i ;scanf("%d",&t);while(t--){head=NULL; scanf("%d",&n);int tmp; for (i=1;i<=n;i++){scanf("%d",&tm[i]); tp.insert(tm[i], head,0);}head->p=0;int m;scanf("%d",&m);for (i=1;i<=m;i++){scanf("%d",&tmp);if (tmp!=tm[1]) tp.query(tmp,head);printf("\n");}} return 0;}
0 0
- hdu5444-Elven Postman-最最朴素的二叉搜索树
- HDU5444 Elven Postman(搜索二叉树模板)
- hdu5444 Elven Postman(二叉树遍历)
- hdu5444 Elven Postman 二叉树建树
- hdu5444 Elven Postman 二叉树遍历
- HDU5444-二叉树模拟-Elven Postman
- HDU5444 - Elven Postman (树的遍历)
- 2015网络赛&HDU5444 Elven Postman - 排序二叉树
- DFS hdu5444 Elven Postman
- hdu5444 Elven Postman
- hdu5444 Elven Postman
- hdu 5444 Elven Postman(搜索二叉树)
- hdu 5444 Elven Postman(二叉搜索树)
- hdu5444 Elven Postman(SBT)
- HDU5444(2015长春网赛)——Elven Postman(树的遍历,dfs)
- hdu 5444 Elven Postman(二叉搜索树)
- hdu 5444 Elven Postman(二叉树的遍历)
- HDU 5444 Elven Postman (二叉树)
- [Android UI开发] Android 性能调优点
- MEAN 框架 解析 及安装步骤
- Android自定义RatingBar(评分控件)
- hdu1452因子和的积性函数
- css2选择器写法大全
- hdu5444-Elven Postman-最最朴素的二叉搜索树
- lintcode-两数之和-56
- sizeof(结构体)的值
- Android系统架构、JVM和DalvikVM的区别
- struts2如何获取数据
- DLX精确覆盖 poj2676 Sudoku
- linux 基础
- 209 Minimum Size Subarray Sum
- 逆向教程->当乐启动图分析手记