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

prim算法做此题,为何一直WA!!

Posted by 987654OPK at 2013-03-20 22:26:17 on Problem 1789
#include<iostream>
using namespace std;
int arr[2010][2010];
char type[2010][10];
int main()
{
	int N,num;
	while(cin>>N&&N)
	{
		bool flag[2010];
		int c[2010];
		memset(flag,0,sizeof(flag));
		memset(c,0,sizeof(c));
		for(int i=1;i<2010;i++)
			for(int j=1;j<2010;j++)
				arr[i][j]=999;
		for(int i=1;i<=N;i++)
		{
			cin>>type[i];
			for(int j=1;j<=i;j++)
			{
			    num=0;
				for(int k=0;k<7;k++)
				{
					if(type[i][k]!=type[j][k])
				    num++;
				}
				arr[i][j]=num;
				arr[j][i]=num;
			}
		}
		flag[1]=true;
		int u=0,dist=0;
		for(int i=2;i<=N;i++)
			c[i]=arr[1][i];
		for(int j=1;j<N;j++)
		{
			int min=9999999;
			for(int i=2;i<=N;i++)
			{
				if(c[i]<min&&!flag[i])
				    u=i;
					min=c[i];
		    }
			flag[u]=true;
			dist+=min;
			for(int k=1;k<=N;k++)
				if(arr[u][k]<c[k]&&!flag[k])
					c[k]=arr[u][k];
		}
		cout<<"The highest possible quality is 1/"<<dist<<"."<<endl;
	}
	//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