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

关于定义的数组名问题

Posted by Blur at 2011-04-08 22:49:38 on Problem 3278
以下两段代码,第1段可以过,第2段是把数组vi[N]与st[N]的名字改成v[N]与s[N],就总RE,有没有人知道怎么回事?
1.
#include<iostream>  
#include<queue>
#define N 100001
using namespace std;

queue<int> x;
bool vi[N];
int st[N];

int bfs(int n,int k)
{
	int head,next;
	x.push(n);
	vi[n]=true;
    st[n]=0;
	while(!x.empty())
	{
		head=x.front();
		x.pop();
		for(int i=0;i<3;i++)
		{
			if(i==0) next=head-1;
			else if(i==1) next=head+1;
			else next=head*2;
			if( next>N || next<0) continue;
			if(!vi[next])
			{
				x.push(next);st[next]=st[head]+1;
				vi[next]=true;	
				
			}
			if(next==k) return st[next];
		}
			
	}
		
}

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	if(n>=k) printf("%d\n",n-k);
	else 
	{
		printf("%d\n",bfs(n,k));	
	}
	return 0;	
}

2.
#include<iostream>  
#include<queue>
#define N 100001
using namespace std;

queue<int> x;
bool v[N];
int s[N];

int bfs(int n,int k)
{
	int head,next;
	x.push(n);
	v[n]=true;
    s[n]=0;
	while(!x.empty())
	{
		head=x.front();
		x.pop();
		for(int i=0;i<3;i++)
		{
			if(i==0) next=head-1;
			else if(i==1) next=head+1;
			else next=head*2;
			if( next>N || next<0) continue;
			if(!v[next])
			{
				x.push(next);s[next]=s[head]+1;
				v[next]=true;	
				
			}
			if(next==k) return s[next];
		}
			
	}
		
}

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	if(n>=k) printf("%d\n",n-k);
	else 
	{
		printf("%d\n",bfs(n,k));	
	}
	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