Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

线段树查找,WA不停,实在是找不出来怎么错了,路过的大牛行行好,帮忙看看提提意见

Posted by aliu0932 at 2009-05-22 21:20:42 on Problem 2182 and last updated at 2009-05-22 21:23:39
#include<stdio.h>
#define N 8001
struct	Node{
	int s,t,nlen;
}node[2*N];
void creatTree(int s,int l,int r)
{
	node[s].s=l,node[s].t=r;
	node[s].nlen=r-l+1;
	if(r>l)	{
		int m=(r+l)>>1;
		creatTree(2*s,l,m);
		creatTree(2*s+1,m+1,r);
	}
}
int search(int pos,int s)
{
	node[s].nlen--;
	if(node[s].s!=node[s].t)	{
		if(pos<=node[2*s].nlen)	return search(pos,2*s);
		else	return search(pos-node[2*s].nlen,2*s+1);
	}
	return node[s].s;
}

int main()
{
//	freopen("data.txt","r",stdin);
	int n,i,a[N],b[N];
	scanf("%d",&n);
	a[1]=0;
	for(i=2;i<=n;i++)
		scanf("%d",&a[i]);
	creatTree(1,1,n);
	for(i=n;i>=1;i--)
		b[i]=search(a[i]+1,1);;
	for(i=1;i<=n;i++)
		printf("%d\n",b[i]);
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator