您的位置:首页 > 其它

网赛 HDU 5444 Elven Postman

2015-09-29 20:50 357 查看
题目意思 :

 排序二叉树,直接上就行了

CODE

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
using namespace std;
struct node
{
int x;
struct node *l, *r;
};
char mp[1010][1010];
node *head;
void juge()///小的是右边E
{
node *tail,*q;
q = new node;
scanf("%d",&q->x);
q->l = NULL;
q->r = NULL;
tail = head;
int cnt = 0;
while(tail)
{
if(tail->x > q->x)
{ mp[q->x][cnt++] = 'E';
if(tail->r)
tail = tail->r;
else
{
tail->r = q;
return;
}

}
else
{ mp[q->x][cnt++] = 'W';
if(tail->l)
tail = tail->l;
else
{
tail->l = q;
return;
}

}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(mp,'\0',sizeof(mp));
int n;
scanf("%d",&n);
int i;
head = new node;
scanf("%d",&head->x);
head->l = NULL;
head->r = NULL;
for(i = 1; i < n; i++)
{
juge();
}
int m;
scanf("%d",&m);
for(i = 0; i < m; i++)
{
int b;
cin>>b;
cout<<mp[b]<<endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: