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

哪位高手能给出边界的测试数据,一直找不出错误

Posted by fengzhizi at 2007-08-18 20:39:41 on Problem 2421
#include<stdio.h>
#define N 200
#define max 10000
int power[N][N]={0};//权值数组
bool search[N]={false};
int closest[N]={0};//记录点v 到S 中的最近点
int lowcost[N]={0};//记录点v 到S 中的最近点的距离
int main()
{
	int i,j;
	int point;
	while(scanf("%d",&point)!=EOF)
	{
		for(i=1;i<=point;i++)
		{
			for(j=1;j<=point;j++)
				scanf("%d",&power[i][j]);
		}
		
		for(i=1;i<=point;i++)
		{
			closest[i]=1;
			lowcost[i]=power[i][1];
			search[i]=false;
		}
		search[1]=true;
	
		int Q;
		scanf("%d",&Q);
		int a,b;//接受输入的两个顶点及权值
		for(i=1;i<=Q;i++)
		{
			scanf("%d%d",&a,&b);
			search[a]=true;
	    	search[b]=true;	
		}
		
		
		for(i=1;i<=point&&search[i];i++)
		{
			for(j=1;j<=point;j++)
			{
				if((lowcost[j]>power[j][i])&&!search[j])
				{
					lowcost[j]=power[j][i];
					closest[j]=i;
				}
			}
		}	
		int cost=0;//记录最小生成树的总代价
		for(i=1;i<=point;i++)
		{
			int temp=max;
			int index=1;//记录找出的结点
			for(j=1;j<=point;j++)
			{
				if((lowcost[j]<temp)&&!search[j])
				{
					temp=lowcost[j];
					index=j;
				}
			}
			search[index]=true;
			cost+=power[index][closest[index]];
			for(j=1;j<=point;j++)
			{
				if((lowcost[j]>power[j][index])&&!search[j])
				{
					lowcost[j]=power[j][index];
					closest[j]=index;
				}
			}
		}
		printf("%d\n",cost);
	}
	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