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

Re:WHY I got WA?

Posted by shouhm at 2005-07-10 14:11:32 on Problem 2472
In Reply To:WHY I got WA? Posted by:shouhm at 2005-07-10 14:11:11
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <stdio.h>
using namespace std;

const int maxn = 101;

double pro[maxn][maxn];
int n, m;
double dis[maxn];
bool mark[maxn];

void init()	{
	int i, j, x, y, d;
	cin >> m;
	for (i = 1; i <= m; i ++)	{
		cin >> x >> y >> d;
		pro[x][y] = double(d) / 100;
        	pro[y][x] = double(d) / 100;
	}
}

void work()	{
	int i, j, p;
	double max1;
	
	memset(mark, false, sizeof(mark));
	for (i = 2; i <= n; i ++)	dis[i] = pro[1][i];
	mark[1] = true;	dis[1] = 1;
	for (i = 2; i <= n; i ++)	{
		max1 = 0;	p = 0;
		for (j = 1; j <= n; j ++)
			if ((!mark[j]) && (dis[j] > max1))	{
				max1 = dis[j];
				p = j;
			}
		if (p == 0)	break;
		mark[p] = true;
		for (j = 1; j <= n; j ++)
			if ((!mark[j]) && (dis[p] * pro[p][j] > dis[j]))
				dis[j] = dis[p] * pro[p][j];
	}
}

void print()	{
	printf("%.6f percent\n", dis[n] * 100);
}

int main()	{
	for (cin >> n; n != 0; cin >> n)	{
		init();
		work();
		print();
	}
	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