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

怎么过不了,老是wrong 想看看牛人怎么写的

Posted by lagrange at 2005-05-03 01:08:55 on Problem 2421
#include <stdio.h>
#define MAXN 101
int n,q,xx[MAXN][MAXN];

void conn(int a,int b)
{
    int i,j,i0,j0,temp;
    if (a<b)
     {temp=a;a=b;b=temp;}
    for(i=1;i<=n;i++)
    {
      xx[b][i]=((xx[a][i]<xx[b][i])?xx[a][i]:xx[b][i]);
      xx[i][b]=((xx[i][a]<xx[i][b])?xx[i][a]:xx[i][b]);
    }
    for(i=a;i<=n-1;i++)
      for(j=1;j<=n;j++)
        xx[i][j]=xx[i+1][j];
    for(i=1;i<=n-1;i++)
      for(j=a;j<=n-1;j++)
        xx[i][j]=xx[i][j+1];
    n--;
}

void input()
{
    int i,j,a,b;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
      for(j=1;j<=n;j++)
        scanf("%d",&xx[i][j]);
    }
    scanf("%d",&q);
    for(i=1;i<=q;i++)
    {
        scanf("%d%d",&a,&b);
        conn(a,b);
    }    
}

int solve()
{
    int i,j,ci,cj,y,min;
    y=0;
    while(n!=1)
    {
        min=10000;
        for(i=1;i<=n;i++)
          for(j=1;j<=n;j++)
            if(xx[i][j]<min&&i!=j)
            {
              min=xx[i][j];
              ci=i;cj=j;
            }
        y+=xx[ci][cj];
        conn(ci,cj);
    }
    return y;
}

main()
{
    input();
    printf("%d\n",solve());
}    

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