<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    一切皆可抽象

    大而無(wú)形 庖丁解牛 厚積薄發(fā) 滌慮玄覽
       ::  ::  ::  ::  :: 管理

    結(jié)果
    順時(shí)針

    01   02   03   04  

    10   11   12   05  

    09   08   07   06  

    逆時(shí)針

    04   03   02   01  

    05   12   11   10  

    06   07   08   09  

    代碼
    public class test {
      public test() {
      }
      private static int[][] data = null;

      private int datai = 1;    //數(shù)值
      private static int  h =0, i=0, j;
      private int row1 =0,col1 =0,row2=0,col2=0;
     
      static int x=3,y=4;    // x=? y=?

      public static void main(String[] args)
      {
         j = y-1;
         data = new int[x][y];  //data init  定義了x行 y列的矩陣 用于存放數(shù)據(jù)
         test t = new test();
         t.input(1);           //開始數(shù)據(jù)塞入 1表示 從左到右
         //數(shù)據(jù)輸出
         System.out.println("順時(shí)針");
         for (int ki=0;ki     {
           for (int kj=0;kj       {

             System.out.print(addZero(String.valueOf(x*y).length(),data[ki][kj])+"   ");
           }
           System.out.println("");
         }


         System.out.println("逆時(shí)針");
         int[][] kk = niuniu(data,x,y); //矩陣倒置
         for (int ki=0;ki     {
           for (int kj=0;kj       {

             System.out.print(addZero(String.valueOf(x*y).length(),kk[ki][kj])+"   ");
           }
           System.out.println("");
         }


      }

      private  void input(int typej)
      {
         if (datai > x*y)
         {
           //System.out.println("exit");如果數(shù)據(jù)塞入到頭 退出遞歸
         }
         else
         {


          //從左到右塞入數(shù)據(jù)
          if (typej == 1) {
             for (int k = i; k <= j; k++) {
               data[h][k] = datai++;
             }

             row1++;  //上面走了一行
             h = y - 1 - col1;  //下一步從上到下表示的列值
             i = row1;          //行起始
             j = x - 1 - col1;  //行終止
             input(2);         //從上到下遍歷數(shù)據(jù)
           }

           //從上到下塞入數(shù)據(jù)
           if ( typej == 2) {
             for (int k = i; k <= j; k++) {
                data[k][h] = datai++;
              }

             col1++;  //左邊走了一列
             h = x - 1 - row2;  //下一步從右到左表示的行值
             i = y - 1 - col1;  //列起始
             j = col2;          //列終止
             input(3);          //從右到左遍歷數(shù)據(jù)
           }

           //從右到左塞入數(shù)據(jù)
           if ( typej == 3) {
             for (int k = i; k >= j; k--) {
               data[h][k] = datai++;
             }

             row2++;  //下面走了一行
             h = col2;  //下一步從下到上表示的列值
             i = x - 1 - row2;   //行起始
             j = row1;           //行終止
             input(4);           //從下到上遍歷數(shù)據(jù)
           }

           //從下到上塞入數(shù)據(jù)
           if (typej == 4) {
             for (int k = i; k >= j; k--) {
               data[k][h] = datai++;
             }

             col2++;  //左面走了一列
             h = row1;  //下一步從左到右的行值
             i = col2;   //列起始
             j = y - 1 - col1;  //列終止
             input(1);
           }
         }
      }

        //補(bǔ)位
        public static String addZero(int weishu, int num) {
        /* int num=new Integer(num).intValue();*/
        int len = Integer.toString(num).length();
        if (len >= weishu) {
          return Integer.toString(num);
        }
        int i = 0;
        int j = weishu - len;
        String BH = "";
        while (i < j) {
          BH = "0" + BH;
          i = i + 1;
        }
        BH = BH + Integer.toString(num);
        return BH;
      }

      //列copy,第1列和最后一列互換 依次類推
      public static int[][] niuniu(int[][] temp,int xi,int yi)
      {
        int[][] rs = new int[xi][yi];
        int foxi = yi/2;
        for (int i=0;i    {
          for (int j=0;j      {
            rs[j][yi-1-i] = temp[j][i];
          }
        }
        int col = foxi-1;
        int k = 0;
        if (yi%2 == 0)
        {
          k = foxi;
        }
        else
        {
          k = foxi +1;
        }
        for (int i=k;i<=yi-1;i++)
        {
          for (int j=0;j      {
            rs[j][col] = temp[j][i];
          }
          col--;
        }

        if (yi%2 == 0)
        {
        }
        else
        {
         for (int j=0;j     {
          rs[j][foxi] = temp[j][foxi];
         }

        }

        return rs;
      }


    }


    評(píng)論

    # re: 關(guān)于一個(gè)矩陣算法  回復(fù)  更多評(píng)論   

    2005-09-05 19:46 by Pudgy's World
    這個(gè)就是螺旋虧陳矩陣吧。

    # re: 關(guān)于一個(gè)矩陣算法  回復(fù)  更多評(píng)論   

    2005-09-05 19:49 by 鋒出磨礪
    對(duì) 算法比較老土 。如果誰(shuí)有更好的 請(qǐng)貼出共同參考學(xué)習(xí)。

    # re: 關(guān)于一個(gè)矩陣算法  回復(fù)  更多評(píng)論   

    2005-09-06 11:36 by ^ Mustang ^
    我們當(dāng)初C語(yǔ)言考試的大題里有一道這樣的

    # re: 【原創(chuàng)】關(guān)于一個(gè)矩陣算法  回復(fù)  更多評(píng)論   

    2006-05-29 20:19 by 月?lián)?/a>
    class Test5{
    public static void main(String[] args){
    final int count = 10;
    int k = 1;
    int[][] a = new int[count][count];
    for (int n = 0; n<(count+1)/2; n++){ //從外往里需要(count+1)/2圈
    for (int i = n; i<count - n; i++){ //上橫行
    a[i][n] = k++;
    }
    for (int i = n + 1; i<count - n; i++){ //右豎行
    a[count-n-1][i] = k++;
    }
    for (int i = count-n-2; i>=n; i--){ //下橫行
    a[i][count-n-1] = k++;
    }
    for (int i = count-n-2; i>n; i--){ //左豎行
    a[n][i] = k++;
    }
    }
    for (int i = 0; i<count; i++){
    for (int j = 0; j<count; j++)
    System.out.print (a[i][j] + " ");
    System.out.println ();
    }
    }
    }
    我們老師寫的。
    主站蜘蛛池模板: 中文字幕无线码中文字幕免费| 中文字幕无码不卡免费视频| 国产在线观看免费完整版中文版 | 亚洲AV人无码综合在线观看| 五月天国产成人AV免费观看| 免费一级一片一毛片| 国产精品亚洲小说专区| 精品熟女少妇AV免费观看| 亚洲av成人综合网| 妞干网免费观看视频| 亚洲aⅴ无码专区在线观看| 国产91久久久久久久免费| 日韩毛片免费一二三| 亚洲午夜久久久久久噜噜噜| a毛片久久免费观看| 亚洲91av视频| 无码免费午夜福利片在线| 亚洲国产综合AV在线观看| 亚洲成a人在线看天堂无码| 免费看黄的成人APP| 亚洲国产模特在线播放| 免费激情视频网站| 一级日本高清视频免费观看| 国产精品久久久亚洲| 99久久99久久精品免费看蜜桃| 亚洲综合无码AV一区二区| 桃子视频在线观看高清免费视频| 国产jizzjizz视频免费看| 中文字幕av免费专区| 亚洲精品**中文毛片| 国产特级淫片免费看| 中文字幕无码一区二区免费| 久久久久亚洲国产| 亚洲日韩精品一区二区三区| 国产成人免费在线| 羞羞视频免费网站含羞草| 亚洲av丰满熟妇在线播放| 免费看的成人yellow视频| 成全视频高清免费观看电视剧| 亚洲中文久久精品无码| 中文字幕免费在线|