在prim一个地方把y写i,悲催!水题直接上代码
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=1e9;
int map[2005][2005];
int vis[2005],low[2005];
void inti(int n)
{
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
map[i][j]=INF;
for(int i=0;i<n;i++)map[i][i]=0;
}
void prim(int from,int n)
{
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)low[i]=map[from][i];
low[from]=0;
vis[from]=1;
for(int i=0;i<n;i++){
int x,MIN=INF;
for(int y=0;y<n;y++)
if(!vis[y]&&low[y]<MIN)
MIN=low[x=y];
vis[x]=1;
for(int y=0;y<n;y++){
if(!vis[y]&&low[y]>map[x][y])
low[y]=map[x][y];
}
}
}
char str[2005][7];
int main()
{
//freopen("int.txt","r",stdin);
int n,cas;
while(~scanf("%d",&n)&&n){
cas=0;
while(cas!=n){
scanf("%s",str[cas++]);
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
int diff=0;
for(int k=0;k<7;k++)
if(str[i][k]!=str[j][k])
diff++;
map[i][j]=map[j][i]=diff;
//printf("i:%d,j:%d %d\n",i,j,diff);
}
}
prim(0,n);
int sum=0;
for(int i=0;i<n;i++)sum+=low[i];
printf("The highest possible quality is 1/%d.\n",sum);
}
return 0;
}