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

POJ 支持多线程吗,我并行计算一下 结果出错了

Posted by qqlook at 2011-10-13 10:32:45 on Problem 1007
POJ 支持多线程吗,我并行计算一下 结果出错了

就这种复杂度 当然 并行意义不大。主要是出于测试的目的 。
代码如下  请各位大大们审阅。
本地测试通过 JAVA 1.6

package poj.c1007;
import java.io.*;
import java.util.*;

public class Whocare
{
	
	public static void main(String[] args)
	{
		System.out.println("222");
	    Scanner cin=new Scanner(System.in);
	    int a=cin.nextInt(),b=cin.nextInt();
	    ArrayList<Gene> genelib= new ArrayList<Gene>();
	    Vector<Inverses> mach= new Vector<Inverses>();
	    int flag=0;
	    for(int i = 0 ; i<b ;i++)
	    {
	    	Gene g=new Gene();
	    	g.index=i;
	    	g.count=0;
	    	g.gene=cin.next();
	    	mach.add( new Inverses(g));
	    	genelib.add(g);
	    }
	    Iterator<Gene> x=  genelib.iterator();
	    while(!mach.isEmpty())
	    {
	    	Enumeration<Inverses> k = mach.elements();
	    	while(k.hasMoreElements())
	    	{
	    		Inverses l=k.nextElement();
	    		if(!l.isAlive())
	    		{
	    			mach.remove(l);
	    		}
	    	}
	    }
//	    while (x.hasNext())
//	    {
//	    	Gene g=x.next();
//	    	System.out.println(g.gene+" "+g.count);
//	    }
	    ComparatorGene cp= new ComparatorGene();
	    Collections.sort(genelib, cp);
	    Iterator<Gene> x2=  genelib.iterator();
	    while (x2.hasNext())
	    {
	    	Gene g=x2.next();
	    	System.out.println(g.gene);
	    }
	    
	}
}

class ComparatorGene implements Comparator<Gene>
{

	@Override
	public int compare(Gene o1, Gene o2)
	{
		if(o1.count.compareTo(o2.count)>0)
			return 1;
		else if(o1.count.compareTo(o2.count)<0)
			return -1;
		else if(o1.index.compareTo(o2.index)>0)
			return 1;
		else return -1;
	}
}

class Gene
{
	public Integer index;
	public Integer count;
	public String gene;
	
}

class Inverses extends Thread {
    boolean runFlag = true;
    boolean alive=true;
    Gene g;
    Inverses(Gene g) {
    	this.g=g;
    	start(); 
    }
    public void run() {
    	for(int i = 0; i<g.gene.length() ; i++)
    	{
    		for(int j=i; j<g.gene.length();j++)
    		{
    			if(g.gene.charAt(i)>g.gene.charAt(j))
    			{
    				g.count ++;
    			}
    		}
    	}
   // 	System.out.println(g.gene+" "+g.count);
    }
  }
  

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