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

Posted by tangbohu222 at 2011-04-01 21:11:55 on Problem 1062
#include <stdio.h>
#include <iostream>
#include <memory.h>
using namespace std;
int diff,n;
int price[105];//每件物品的价格
int num;
int distan[105][105];//两个节点直接的距离
int cla[105];//等级
int use[105];//是否已经使用
int v[105];
const int MAX=10000000;
void dijkstra(int l,int r)//先不考虑每个节点的值
{
	for (int i=1;i<=n;i++)
	{
		if(l<=cla[i]&&cla[i]<=r)
			continue;
		else use[i]=0;
	}
	
	for (int i=2;i<=n;i++)
	{
		v[i]=distan[1][i];
	}
	use[1]=0;
	for(int i=2;i<=n; i++)
	{
		int MIN=MAX;
		int t=0;

		for(int j=2;j<=n; j++)
		{
			if(use[j]&&v[j]<MIN)
			{
				MIN =v[j];
				t=j;
			}
		}
		if(!t)
			break;
		use[t]=0;
		for(int j=2;j<=n; j++)
		{
			if(use[j]&&(MIN+distan[t][j] < v[j]))
			{
				v[j]=MIN+ distan[t][j];
			}
		}
	}

}
int main()
{
	//freopen("C:/Users/bohu/Desktop/a.in","r",stdin);
	int temp1,temp2,temp3,l1;
	while (scanf("%d%d",&diff,&n)!=EOF)
	{
		for (int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
				distan[i][j]=MAX;
		}
		distan[1][1]=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d%d",&temp1,&temp2,&temp3);
			cla[i]=temp2;
			use[i]=1;
			price[i]=temp1;
			num=temp3;
			for (int j=0;j<num;j++)
			{
				scanf("%d",&l1);
				scanf("%d",&distan[i][l1]);
			}
		}
		int ans=MAX;
		for(int j =cla[1]-diff; j<=cla[1];j++)   //枚举各种可能
		{
			dijkstra(j,j+diff);
			for (int i=1;i<=n;i++)
			{
				if (v[i]+price[i]<ans)
				{
					ans=v[i]+price[i];
				}
			}
			memset(use,1,sizeof(use));
		}


		printf("%d\n",ans);
	}
	
	//fclose(stdin);
	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