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

第一次做图…一次AC…上代码…未优化,勿喷~~错误之处还望指出,谢谢~~

Posted by wsj19911101 at 2010-11-25 15:25:44 on Problem 2421
#include<iostream>
using namespace std;
int a[100][100];
int t[100];
int main()
{ 
	memset(t,0,sizeof(t));
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)cin>>a[i][j];
	int m;
	cin>>m;
	int x,y;
	int sum=0;
	for(int i=0;i<m;i++){cin>>x>>y;a[x-1][y-1]=0;a[y-1][x-1]=0;}
	t[0]=1;
	for(int i=2;i<=n;i++)
	{
		int min=1001;
		for(int j=0;j<n;j++)
			if(t[j])
			{
				for(int k=1;k<n;k++)if(t[k]==0)
				{
					if(a[j][k]<min){min=a[j][k];x=j;y=k;}
				}
			}
		t[y]=1;
		sum+=min;
	}
	cout<<sum<<endl;
}

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