hdu 5444 Elven Postman
来源:互联网 发布:业绩查询系统源码 编辑:程序博客网 时间:2024/05/16 12:32
写这道题目是想练练静态的二叉查找树
#include<iostream>#include<cstdio>#include<cstdlib>#include<vector>#include<cmath>#include<string>#include<algorithm>#include<set>#include<map>#include<cstring>#include<queue>#include<stack>#include<list>using namespace std;typedef long long ll;const int maxn=1000+5;const ll inf=1e9;const ll mod=1e9+7;struct tree{ int root,childs[maxn][2]; int node[maxn],cnt; void start(){ memset( childs,0,sizeof(childs) ); memset(node,0,sizeof(node)); cnt=1; root=0; } void insert( int &fa,int x ){ if( fa==0 ){ node[cnt]=x; fa=cnt++; childs[fa][0]=childs[fa][1]=0; } else if( node[fa]==x ){ return ; } else if( node[fa]>x ){ insert( childs[fa][0],x ); } else if( node[fa]<x ){ insert( childs[fa][1],x ); } } void find( int fa,int x ){ if( node[fa]==x )return ; if( x<node[fa] ){ printf("E"); find( childs[fa][0],x ); } else if( x>node[fa] ){ printf("W"); find( childs[fa][1],x ); } }};tree t;int main(){ int T; scanf("%d",&T); while(T--){ int n; scanf("%d",&n); t.start(); for(int i=0;i<n;i++){ int x; scanf("%d",&x); t.insert(t.root,x); } int p; scanf("%d",&p); for(int i=0;i<p;i++){ int x; scanf("%d",&x); t.find(t.root,x); printf("\n"); } }return 0;}
0 0
- hdu 5444 Elven Postman
- hdu 5444 Elven Postman
- hdu 5444 Elven Postman
- hdu 5444 Elven Postman
- HDU 5444 Elven Postman
- HDU 5444 Elven Postman
- HDU-5444 Elven Postman
- HDU 5444 Elven Postman
- HDU 5444 Elven Postman
- HDU 5444 Elven Postman
- hdu 5444 Elven Postman
- hdu 5444 Elven Postman
- hdu 5444 Elven Postman(模拟)
- hdu 5444 Elven Postman (DFS)
- 网赛 HDU 5444 Elven Postman
- hdu 5444 Elven Postman 水题- -
- HDU 5444 Elven Postman 二叉排序树
- Hdu 5444 Elven Postman dfs
- 深入研究SSL【第二章 part-1】-SSL握手协议的研究
- 15 个 Android 通用流行框架大全
- linux命令 ls
- 浅析Java中的装箱和拆箱
- js高性能循环
- hdu 5444 Elven Postman
- android java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
- Firebug控制台调试程序
- @NotNull、@NotEmpty、@NotBlank的区别
- Printers(一) 打印机配置信息
- 飞机大战整理
- 深入研究SSL【第二章 part-2】-SSL握手协议的研究
- Suggestion: add 'tools:replace="android:icon"' to element
- 使用splice删除数组时,需要注意的地方