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

测了 n =3 再继续测n=4你就知道了

Posted by bigyellow at 2007-10-04 13:19:44 on Problem 1258
In Reply To:这么简单的题目为什么给我WA??难道我PRIM错了??? Posted by:kikif at 2007-09-14 10:42:20
> #include <iostream>
> #include <fstream>
> using namespace std;
> 
> int n;
> int mark[110];
> int cost[110][110];
> 
> int total;
> 
> 
> void prim(){
> 	mark[1]=1;
> 	int dest[110];
> 	int i,j,k;
> 
> 	for(i=2;i<=n;i++){
> 		dest[i]=cost[1][i];
> 	}
> 	for(i=1;i<n;i++){
> 		int min=1000000;
> 		int node=-1;
> 		for(j=1;j<=n;j++){
> 			if(mark[j]==0&&dest[j]<min){
> 				min=dest[j];
> 				node=j;
> 			}
> 		}
> 		mark[node]=1;
> 		total+=min;
> 		for(j=1;j<=n;j++){
> 			if(mark[j]==0&&dest[j]>cost[node][j]){
> 				dest[j]=cost[node][j];
> 			}
> 		}
> 
> 	}
> }
> 
> 
> 
> 
> void main(){
> //	ifstream cin("data.txt");
> 	while(cin>>n){
> 		int i,j,k;
> 
> 		for(i=1;i<=n;i++){
> 			for(j=1;j<=n;j++){
> 				cin>>cost[i][j];
> 			}
> 		}
> 		total=0;
> 		prim();
> 		cout<<total<<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