网赛 HDU 5444 Elven Postman

来源:互联网 发布:通达信股票行情软件 编辑:程序博客网 时间:2024/05/21 06:14

题目意思 :

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

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;}


0 0
原创粉丝点击