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 bellman做的- -好心人看看

Posted by allen4053040allen at 2010-05-19 10:27:54 on Problem 1860
#include<iostream>

using namespace std;

#define MAX 202
#define Inf 100000000

double d[MAX];
double R[MAX][MAX], C[MAX][MAX];

double w(int a, int b)
{
	return - ((d[a] - C[a][b]) * R[a][b] - d[a]);   //加负号  则形成负环就是赚了
}

int main()
{
	int n, t, k;
	int i, j, p;
	int A, B;
	double RAB, CAB, RBA, CBA;
	double h;
	scanf("%d%d%d%lf", &n, &t, &k, &h);
	//cout << "<->" << endl;
	//getchar();
	while(t --) {
		//cout << "---" << endl;
		getchar();
		scanf("%d%d%lf%lf%lf%lf", &A, &B, &RAB, &CAB, &RBA, &CBA);   //不能输入R[A][B] - -!
		R[A][B] = RAB;
		C[A][B] = CAB;
		R[B][A] = RBA;
		C[B][A] = CBA;
	}
	for(i = 1; i <= n; i ++)
		d[i] = Inf;
	d[k] = h;
	for(p = 1; p < n; p ++)
		for(i = 1; i <= n; i ++)
			for(j = 1; j <= n; j ++) {
				if(i == j)
					continue;
				if(d[i] < Inf && d[j] > d[i] + w(i, j)) {
					//printf("%lf\n", w(i, j));
					d[j] = d[i] + w(i, j);
					//relax = 1;
				}
			}
	for(i = 1; i <= n; i ++) {
		for(j = 1; j <= n; j ++)
			if(d[j] > d[i] + w(i, j)) {
				printf("YES\n");
				system("pause");
				return 0;
			}
	}
	printf("NO\n");
	system("pause");
	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