ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

WHY WA? Problem 1136 -> Parliament
Posted by Algorist 24 Dec 2001 19:12

#include <iostream>
#include <cstring>
using namespace std;

struct treetag {
 int left, right;
} tree[60001];

int n,inp[3001];
int done=0;

void leftt(int l, int r,int root);
void rightt(int l,int r,int root);
void print(int root);

int
main() {
int rt;

 memset(&tree, 0 , sizeof(tree));
 cin>> n;
 for (int i=1;i<=n;i++)
     cin>> inp[i];
 rt=inp[n];

 leftt (1,n,rt);
 rightt(1,n,rt);

 print(rt);
 cout<<endl;
 return 0;
}

void leftt(int l, int r,int root) {
int i=l;
 if (l>r) return;
 while (inp[i]<root) i++;
 i--;
 if ((inp[i]>=root)||(i<l)) return;
 tree[root].left=inp[i];
 leftt(l,i,inp[i]);
 rightt(l,i,inp[i]);

}


void rightt(int l,int r,int root) {
int i=r;
 if (l>r) return;
 while (inp[i]>=root) i--;
 i++;
 if ((inp[i]<=root)||(i>r)) return;
 tree[root].right=inp[r-1];
 leftt(i,r-1,inp[r-1]);
 rightt(i,r-1,inp[r-1]);

}

void print(int root) {
 if ((tree[root].left!=0)||(tree[root].right!=0)) {
  if (tree[root].right!=0) print(tree[root].right);
  if (tree[root].left!=0) print(tree[root].left);
 }
 if (done!=1) cout<< " ";
 cout<< root;
 done=1;
}
Why don't you send email to "hyz12345678@163.com".
Posted by Huang Yizheng 25 Dec 2001 06:46
>
> #include <iostream>
> #include <cstring>
> using namespace std;
>
> struct treetag {
>  int left, right;
> } tree[60001];
>
> int n,inp[3001];
> int done=0;
>
> void leftt(int l, int r,int root);
> void rightt(int l,int r,int root);
> void print(int root);
>
> int
> main() {
> int rt;
>
>  memset(&tree, 0 , sizeof(tree));
>  cin>> n;
>  for (int i=1;i<=n;i++)
>      cin>> inp[i];
>  rt=inp[n];
>
>  leftt (1,n,rt);
>  rightt(1,n,rt);
>
>  print(rt);
>  cout<<endl;
>  return 0;
> }
>
> void leftt(int l, int r,int root) {
> int i=l;
>  if (l>r) return;
>  while (inp[i]<root) i++;
>  i--;
>  if ((inp[i]>=root)||(i<l)) return;
>  tree[root].left=inp[i];
>  leftt(l,i,inp[i]);
>  rightt(l,i,inp[i]);
>
> }
>
>
> void rightt(int l,int r,int root) {
> int i=r;
>  if (l>r) return;
>  while (inp[i]>=root) i--;
>  i++;
>  if ((inp[i]<=root)||(i>r)) return;
>  tree[root].right=inp[r-1];
>  leftt(i,r-1,inp[r-1]);
>  rightt(i,r-1,inp[r-1]);
>
> }
>
> void print(int root) {
>  if ((tree[root].left!=0)||(tree[root].right!=0)) {
>   if (tree[root].right!=0) print(tree[root].right);
>   if (tree[root].left!=0) print(tree[root].left);
>  }
>  if (done!=1) cout<< " ";
>  cout<< root;
>  done=1;
> }