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

求大牛帮我看下3159的代码``不知道哪里错了····

Posted by jieqing at 2011-05-29 22:49:25
#include <iostream>
#include <algorithm>
using namespace std;

struct f
{
	int A, B, C;
}temp[2][150001];

bool cmp(f a, f b)
{
	return a.A < b.A;
}

int main()
{
	int n, m, a, b, c, i = 0, j = 0, k, x, kid[2][30001] = {0};
	cin>>n>>m;
	while (m--)
	{
		cin>>a>>b>>c;
		if (a < b)
		{
			temp[0][i].A = a;
			temp[0][i].B = b;
			temp[0][i].C = c;
			i++;
		}
		else
		{
			temp[1][j].A = b;
			temp[1][j].B = a;
			temp[1][j].C = c;
			j++;
		}
	}
	sort(temp[0], temp[0]+i, cmp);
	sort(temp[1], temp[1]+i, cmp);
	for (k=0; k<i; k++)
	{
		x = kid[0][temp[0][k].A] + temp[0][k].C;
		if (x < kid[0][temp[0][k].B] || 0 == kid[0][temp[0][k].B])
			kid[0][temp[0][k].B] = x;
	}
	for (k=0; k<j; k++)
	{
		x = kid[1][temp[1][k].A] + temp[1][k].C;
		if (x < kid[1][temp[1][k].B] || 0 == kid[1][temp[1][k].B])
			kid[1][temp[1][k].B] = x;
	}
	cout<<max(kid[0][n], kid[1][n])<<endl;
	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