Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我还没学会二叉平衡树的调整,高手们能指点下本题的调整吗?#include <iostream> using namespace std; int lc[15001],rc[15001],point[15001],flag[15001],num[15001],f; int Root; void add(int i,int j,int x) { if(point[x]<point[i]) { num[i]++; if(lc[i]==-1) { lc[i]=x; flag[j]++; f=0; } else{ f=0; add(lc[i],j,x); } } else{ if(rc[i]==-1) { // if(f==0) flag[j+1]++; // else if(f==1) // flag[j]++; rc[i]=x; f=0; } else{ f=1; add(rc[i],num[i]+j+1,x); } } } void show() { } int main() { int i,j,N; while(scanf("%d",&N)!=EOF) { int pos=0; /* if(N==0) { printf("0\n"); continue; }*/ f=0; memset(lc,-1,sizeof(lc)); memset(rc,-1,sizeof(rc)); memset(flag,0,sizeof(flag)); memset(num,0,sizeof(num)); scanf("%d%d",&point[pos],&j); flag[0]++; Root=0; for(pos=1;pos<N;pos++) { scanf("%d%d",&point[pos],&j); add(Root,0,pos); show(); } for(i=0;i<N;i++) cout<<flag[i]<<endl; } return 0; } /* 5 1 1 5 1 7 1 3 3 5 5 */ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator