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

有没有人能帮我看一下为什么我的代码在G++下是对而C++下就WA? 我已经碰到好几次这种问题了..很是郁闷!万分感激!!

Posted by sasnzy at 2006-08-30 19:44:39 on Problem 2983
还有我在st[],en[],w[]和bellman()里面的局部数组变量b[]上多开了5个在G++下交又WA了

#include<iostream>
using namespace std;
const int inf=100000000;

int st[200000],en[200000],w[200000],e,v,E;
char s[1000];

int bellman()
{
	int b[1000],i,j;
	bool f;
	for (i=0;i<v;i++)
		b[i]=inf;
	b[0]=0;
	for (i=1;i<v;i++)
	{
		f=0;
		for (j=0;j<e;j++)
			if (b[st[j]]+w[j]<b[en[j]])
				b[en[j]]=b[st[j]]+w[j],f=1;
		if (!f) return 1;
	}
	return 0;
}
void readdata()
{
	int i,j,a,b,l,dis;
	gets(s);
	e=0;
	for (i=0;i<E;i++)
	{
		gets(s);
		l=strlen(s);
		if (s[0]=='P')
		{
			a=0,b=0,dis=0;j=2;
			while (s[j]!=' ')
				a=a*10+s[j++]-'0';
			j++;
			while (s[j]!=' ')
				b=b*10+s[j++]-'0';
			j++;
			while (j<l)
				dis=dis*10+s[j++]-'0';
			st[e]=a,en[e]=b,w[e]=-dis;
			e++;
			st[e]=b,en[e]=a,w[e]=dis;
			e++;
		}
		else
		{
			a=0,b=0,j=2;
			while (s[j]!=' ')
				a=a*10+s[j++]-'0';
			j++;
			while (j<l)
				b=b*10+s[j++]-'0';
			st[e]=a,en[e]=b,w[e]=-1;
			e++;
		}

	}
}
int main()
{
	while (scanf("%d%d",&v,&E)!=EOF)
	{
		readdata();
		if (bellman())
			printf("Reliable\n");
		else
			printf("Unreliable\n");
	}
}

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