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 zkgogogo at 2009-08-04 17:25:18 on Problem 2421
#include <iostream>
using namespace std;

int N;
int map[101][101];
int h;  //已建的路数

int prim(int s)       //这个prim的写法没问题吧?
{   int i,j=0,k,sum=0,flag=0;
    int d[101];
    
    for(i=1;i<=N;i++)
       d[i]=map[s][i];
        
     d[s]=0;  

    int current=s;
    for(i=1;i<N;i++)
    {   int MIN=INT_MAX;
        for(j=1;j<=N;j++)
        {   if(d[j]&&d[j]<MIN)
            {   current=j;
                MIN=d[j];
            }
        }
        if(MIN!=INT_MAX)
            sum+=MIN;
        d[current]=0;
        for(j=1;j<=N;j++)
            if(map[current][j]&&map[current][j]<d[j])
                d[j]=map[current][j];
    }
    return sum;
}

int main()
{   int i,j,t;
    scanf("%d",&N);
    for(i=1;i<=N;i++)
        for(j=1;j<=N;j++)
        {    scanf("%d",&map[i][j]);
            
        }
    scanf("%d",&h);
    for(i=0;i<h;i++)
    {    scanf("%d%d",&j,&t);
        map[j][t]=0;
        map[t][j]=0;
    }
    int Min=INT_MAX;
    for(i=1;i<=N;i++)
    {   j=prim(i);//枚举所有村庄为起点
        if(j<Min)
            Min=j;
    }
    cout<<Min<<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