网赛 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;
}
排序二叉树,直接上就行了
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;
}
相关文章推荐
- 相册读取照片UIImagePickController
- hdu 5459 Jesus Is Here(dp)
- iOS界面编程-UIProgressView
- 黄半仙算命系统3
- 自定义UITabBardUIButtton上面的UIImageView和UILabel的布局
- 电脑装多系统,启动出现grub rescue,“normal.mod not found”解决办法(windows,ubuntu)
- 第四课 模块、包
- Google Chrome 浏览器怎么找到看完视频之后那个缓存文件 谢谢
- 欢迎使用Markdown编辑器写博客
- objc-internal.h
- boost vc编译
- Nginx配置性能优化
- 翻译单词 Trie POJ 2503 Babelfish
- 《机器学习实战》笔记之十三——利用PCA来简化数据
- 关于缺陷报告
- iOS 核心动画2
- Struts中对通配符的配置说明
- HDU 5480(前缀和||树状数组)
- 获取资源文件方法
- 计算器