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

我的prime有什么不对吗,WA,用JAVA的帮忙看一下呀

Posted by gostopsb at 2007-01-21 22:22:23 on Problem 1258
import java.util.*;
public class P1258
{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		// TODO 自动生成方法存根
        Scanner sc=new Scanner(System.in);
        
        
        
        
      while(sc.hasNext())
      {	  
        int n=sc.nextInt();
        
        int[][] input=new int[n+1][n+1];
        
        int result=0;
        TreeSet<Integer> u=new TreeSet<Integer>();//prime算法里的已经算好的集合
        TreeSet<Integer> v=new TreeSet<Integer>();//未计算的集合
        
       
        u.add(1);  //将第一个节点做为初始节点加入到u中
        for(int i=2;i<=n;i++)//将其余节点加入到v中
        {
        	v.add(i);
        }
        for(int i=1;i<=n;i++)
        {
        	for(int j=1;j<=n;j++)
        	{
        		input[i][j]=sc.nextInt();
        	}
        }
        
       int min=100000;//保存每一步的最小值
       int node = 0;//保存每一步的节点号
       while(!v.isEmpty())
       {
    	   min=100000;
    	   
        for(int i=1;i<=n;i++)
        {
        	for(int j=i+1;j<=n;j++)
        	{
        		if(u.contains(i)&&v.contains(j))
        		{
        			if(input[i][j]<min)
        			{
        				min=input[i][j];
        				node=j;
        				
        			}
        			
        			
        		}
        	}
        }
        
        result+=min;
        
        
        
        u.add(node);
        v.remove((Integer)node);
        
       }
       
          System.out.println(result);
       
          
              
      }
	}

}

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