zoukankan      html  css  js  c++  java
  • java作业不能运行

    import java.util.Scanner;


    public class zhsh_nhh extends Thread{

     /**
      * @param args
      */
     private int n,start,end;
     public int q;
     public int[][] zhshQ=new int[10000][22];
     int[] b=new int[22];
     public zhsh_nhh(int x,int start,int end)
     {
      this.q=0;
      this.start=start;
      this.end=end;
      this.n=x;
     }
     public void out(int ans)
     {
      for(int i=1;i<=n;i++)
      {
       for(int j=1;j<=n;j++)
        if(zhshQ[ans-1][i]==j)
         System.out.print('q');
        else System.out.print('*');
       System.out.print(' ');
       
      }
      
     }

     public void dfs(int k,int b[])
     {
        
         if(k>n)
         {
            
             q++;
            // System.out.println(q+"ddddddddddddd");
             for(int l=1;l<=n;l++)
              zhshQ[q][l]=b[l];
             return ;
         }
         int i,j;
         for(i=1;i<=n;i++)
             {

                for(j=1;j<k;j++)
                {
                    if(i==b[j])
                        break;
                    if(Math.abs(k-j)==Math.abs(i-b[j]))
                        break;
                }
       if(j<k)
                    continue;
               // System.out.print("草泥马"+i);
                 b[k]=i;
                 dfs(k+1,b);
            
             }
     }
     public void run()
     {
      //System.out.print("开始运行我了");
      for(int i=start;i<=end;i++)
      {
       b[1]=i;
       dfs(2,b);
      
      }
      
     }
     public static void main(String[] args) throws InterruptedException {
      // TODO Auto-generated method stub
      Scanner zhshinput=new Scanner(System.in);
      int zhshn=zhshinput.nextInt();
      //并行解法
      //long k=0;
      long begin,end,endend;
      
      //并行解法
      zhsh_nhh t1=new zhsh_nhh(zhshn,1,zhshn/2);
      zhsh_nhh t2=new zhsh_nhh(zhshn,zhshn/2+1,zhshn);
      begin=System.currentTimeMillis();
      t1.start();
      t2.start();
      t1.join();
      t2.join();
      end=System.currentTimeMillis();
      
      
      //串行解法
      zhsh_nhh t=new zhsh_nhh(zhshn,1,zhshn);
      long b=System.currentTimeMillis();
      t.start();
      t.join();
      endend=System.currentTimeMillis();
      
      System.out.println("并行的时间为");
      System.out.println(end-begin);
      System.out.println("串行的时间为");
      System.out.println(endend-b);
      System.out.println("加速比为:"+(endend-b)*1.0/(end-begin)*1.0);
      System.out.println("共有"+t.q+"种解法");
      
      int x;
      int ans;
      System.out.println("请输入要求解的解方法: 1串行解法 2:并行解法 0:退出");
      x=zhshinput.nextInt();
      
      while(x>0)
      {
      
       System.out.println("请输入要求第几种解方法:");
       ans=zhshinput.nextInt();
       if(ans>t.q)
        System.out.println("输入量错误的数据");
       if(x==2)
       {
        if(ans<=t1.q)
        t1.out(ans);
         else
           t2.out(ans-t1.q);
           }
        else if(x==1)
        {
        t.out(ans);
        }
        else System.out.println("输入了错误的数据 ");
       System.out.println("请输入要求解的解方法: 1串行解法 2:并行解法 0:退出");
      }
     }

    }

  • 相关阅读:
    zookeeper的ACL权限控制
    Zookeeper客户端Curator基本API
    get和post的区别
    Html基本操作实例代码
    poj3322 Bloxorz I
    Delphi 调用SQL Server 2008存储过程
    架构设计师—你在哪层楼?
    LINUX常用命令
    分层自动化测试与传统自动化测试的差别
    商业智能漫谈
  • 原文地址:https://www.cnblogs.com/zhangdashuai/p/4112154.html
Copyright © 2011-2022 走看看