to zhgj8750(清风)如果没有就返回0啦。如果有两个一样大的就返回其中的一个。

解决方案 »

  1.   

    to zhgj8750(清风)
     kuai a
      

  2.   

    zem me mei you ren lai
      

  3.   

    我写了一个……
    不过是用C写的……
    很菜……见笑了……
    #include<stdio.h>//设置矩阵宽度
    #define COLUMNCOUNT 5//定义矩形结构
    typedef struct
    {
    int r1, c1, //左上角的点在第r1行,c1列
    r2, c2 ; //右下角的点在第r2行,c2列
    }Rect, *pRect ;int getMaxRects(int base[][COLUMNCOUNT], int rc, pRect result) ;
    int countRectArea(int base[][COLUMNCOUNT], int r1, int c1, int r2, int c2) ;int main()
    {
    //矩阵数据
    int base[][COLUMNCOUNT] =
    {
    1, 0, 0, 1, 0,
    1, 0, 0, 1, 0,
    1, 0, 0, 0, 0,
    1, 0, 0, 1, 0
    } ; //保存结果的数组
    Rect result[20] ; //具有最大面积的面积相同的矩形的数目
    int numCount = getMaxRects(base, sizeof(base)/sizeof(base[0]), &result) ; //显示最大面积
    if(numCount>0)
    printf("最大面积为:%d\n",
    (result[0].r2 - result[0].r1 + 1)
    *(result[0].c2 - result[0].c1 + 1) ) ;
    else printf("晕!竟然为0!\n") ; //显示矩形对角点
    while( --numCount >= 0 )
    printf("(%d,%d),(%d,%d)\n", result[numCount].r1, result[numCount].c1, result[numCount].r2, result[numCount].c2) ; return 0 ;
    }int getMaxRects(int base[][COLUMNCOUNT], int rc, pRect result)
    {
    //得到最大的矩形,矩形结构保存在result里,并返回最大面积的矩形数目 //矩阵宽度
    int cc = COLUMNCOUNT ; int r1, c1, //接受测试的左上角点
    cn, //应测试的右边界
    r2, c2 ; //测试矩形的右下角点 //最大面积
    int maxArea = 0 ;
    //具有最大面积的面积相同的矩形的数目
    int numCount = 0 ;
    //当前测试的矩形的面积
    int ac ; //遍历所有的点
    for(r1 = 0; r1 < rc; ++r1)
    for(c1 = 0; c1 < cc; ++c1)
    if(base[r1][c1] == 0)
    {
    //右边界
    cn = cc ;
    //遍历该点右边界内所有的点
    for(r2 = r1; r2 < rc; ++r2)
    for(c2 = c1; c2 < cn; ++c2)
    //如两点间的矩形符合条件(全0)
    if( (ac = countRectArea(base, r1, c1, r2, c2)) > 0 )
    //发现了更大的矩形
    if(ac > maxArea)
    {
    maxArea = ac ;
    numCount = 1 ;
    result[0].r1 = r1 ;
    result[0].c1 = c1 ;
    result[0].r2 = r2 ;
    result[0].c2 = c2 ;
    }
    //又发现了一个符合大小条件的矩形
    else if( ac == maxArea )
    {
    result[numCount].r1 = r1 ;
    result[numCount].c1 = c1 ;
    result[numCount].r2 = r2 ;
    result[numCount].c2 = c2 ;
    ++numCount ;
    }
    else ;
    else cn = c2 ; //到了右边界
    } return numCount ;
    }int countRectArea(int base[][COLUMNCOUNT], int r1, int c1, int r2, int c2)
    { //测试两点(矩形左上角和右下角)之间是否全为0
    //是则返回面积
    //否则返回0 int i, j ; //测试所有点
    for(i = r1 ; i <= r2 ; ++i)
    for(j = c1 ; j <= c2 ; ++j)
    if( base[i][j] >0 )
    return 0 ; //不为0! //全为0!返回面积
    return (c2 - c1 + 1) * (r2 - r1 +1) ;
    }
      

  4.   

    晕……
    tab符在这里显示会那么找的啊……
    再发……
    #include<stdio.h>//设置矩阵宽度
    #define COLUMNCOUNT 5//定义矩形结构
    typedef  struct
    {
      int r1, c1,    //左上角的点在第r1行,c1列
        r2, c2 ;  //右下角的点在第r2行,c2列
    }Rect, *pRect ;int getMaxRects(int base[][COLUMNCOUNT], int rc, pRect result) ;
    int countRectArea(int base[][COLUMNCOUNT], int r1, int c1, int r2, int c2) ;int main()
    {
      //矩阵数据
      int base[][COLUMNCOUNT] =
      {
        1, 0, 0, 1, 0,
        1, 0, 0, 1, 0,
        1, 0, 0, 0, 0,
        1, 0, 0, 1, 0
      } ;  //保存结果的数组
      Rect result[20] ;  //具有最大面积的面积相同的矩形的数目
      int numCount = getMaxRects(base, sizeof(base)/sizeof(base[0]), &result) ;  //显示最大面积
      if(numCount>0)
        printf("最大面积为:%d\n",
                  (result[0].r2 - result[0].r1 + 1)
                  *(result[0].c2 - result[0].c1 + 1) ) ;
      else printf("晕!竟然为0!\n") ;  //显示矩形对角点
      while( --numCount >= 0 )
        printf("(%d,%d),(%d,%d)\n", result[numCount].r1, result[numCount].c1, result[numCount].r2, result[numCount].c2) ;  return 0 ;
    }int getMaxRects(int base[][COLUMNCOUNT], int rc, pRect result)
    {
      //得到最大的矩形,矩形结构保存在result里,并返回最大面积的矩形数目  //矩阵宽度
      int cc = COLUMNCOUNT ;  int r1, c1,    //接受测试的左上角点
        cn,      //应测试的右边界
        r2, c2 ;  //测试矩形的右下角点  //最大面积
      int maxArea = 0 ;
      //具有最大面积的面积相同的矩形的数目
      int numCount = 0 ;
      //当前测试的矩形的面积
      int ac ;  //遍历所有的点
      for(r1 = 0; r1 < rc; ++r1)
        for(c1 = 0; c1 < cc; ++c1)
          if(base[r1][c1] == 0)
          {
            //右边界
            cn = cc ;
            //遍历该点右边界内所有的点
            for(r2 = r1; r2 < rc; ++r2)
              for(c2 = c1; c2 < cn; ++c2)
                //如两点间的矩形符合条件(全0)
                if( (ac = countRectArea(base, r1, c1, r2, c2)) > 0 )
                  //发现了更大的矩形
                  if(ac > maxArea)
                  {
                    maxArea = ac ;
                    numCount = 1 ;
                    result[0].r1 = r1 ;
                    result[0].c1 = c1 ;
                    result[0].r2 = r2 ;
                    result[0].c2 = c2 ;
                  }
                  //又发现了一个符合大小条件的矩形
                  else if( ac == maxArea )
                  {
                    result[numCount].r1 = r1 ;
                    result[numCount].c1 = c1 ;
                    result[numCount].r2 = r2 ;
                    result[numCount].c2 = c2 ;
                    ++numCount ;
                  }
                  else ;
                else cn = c2 ; //到了右边界
          }  return numCount ;
    }int countRectArea(int base[][COLUMNCOUNT], int r1, int c1, int r2, int c2)
    {  //测试两点(矩形左上角和右下角)之间是否全为0
      //是则返回面积
      //否则返回0  int i, j ;  //测试所有点
      for(i = r1 ; i <= r2 ; ++i)
        for(j = c1 ; j <= c2 ; ++j)
          if( base[i][j] >0 )
            return 0 ;  //不为0!  //全为0!返回面积
      return (c2 - c1 + 1) * (r2 - r1 +1) ;
    }
      

  5.   

    kao, 还没写完, 其实挺简单的..
      

  6.   

    这个算法挺麻烦的…………我写了一个,花了一晚上时间,要判断的情况很多,我就是根据下一行跟上一行比较这个基本思想做的,代码虽然通过,但是觉得……好麻烦啊,估计肯定不是最佳算法。以下是代码:
    import java.util.Vector;/*
     * 创建日期 2005-4-21
     *
     * TODO 要更改此生成的文件的模板,请转至
     * 窗口 - 首选项 - Java - 代码样式 - 代码模板
     *//**
     * @author shenhw
     *
     * TODO 要更改此生成的类型注释的模板,请转至
     * 窗口 - 首选项 - Java - 代码样式 - 代码模板
     */
    public class Matrix {
        public int rowstart;
        public int rowlen;
        public int colstart;
        public int collen;
        public int tmpcolstart;
        public int tmpcollen;
        public boolean endflag;
        public Matrix(int rowstart,int colstart,int collen){        
            this.rowstart = rowstart;
            this.rowlen = 1;
            this.colstart = colstart;
            this.collen = collen;
            this.endflag = false;
            this.tmpcolstart = colstart;
            this.tmpcollen = collen;                    
        }
        
        public Matrix(int rowstart,int colstart,int collen,int rowlen){
            this.rowstart = rowstart;
            this.rowlen = rowlen;
            this.colstart = colstart;
            this.collen = collen;
            this.endflag = false;
            this.tmpcolstart = colstart;
            this.tmpcollen = collen;        
        }
        
        public static Matrix joinMatrix(Matrix m1,Matrix m2,Vector c1,Vector c2,Vector c3){
            Matrix m3=m2;
            int[] tmpi = null;
            Matrix tmp = null;
            Matrix tmp2 = null;
            if(c2.size()==0){            
                if(m1.rowlen>1&&m1.collen*m1.rowlen>m2.collen*m2.rowlen){
                    m3 = m1;
                }
                c1.remove(m1);
            }else{
                for(int i=(c2.size()-1);i>=0;i--){
                    tmp = (Matrix)c2.get(i);
                    if(m1.rowstart+m1.rowlen==tmp.rowstart+tmp.rowlen){
                        tmp2 = new Matrix(m1.rowstart,m1.tmpcolstart,m1.tmpcollen,m1.rowlen-1);
                        tmpi = intersect(tmp,tmp2);
                        if(tmpi[0]!=-1){
                            c3.addElement(new Matrix(m1.rowstart,tmpi[0],tmpi[1],m1.rowlen));
                            c3.addElement(m1);
                            m1 = tmp2;
                            m1.endflag=true;
                            if(tmp2.rowlen>1&&tmp2.collen*tmp2.rowlen>m2.collen*m2.rowlen){
                                m3 = tmp2;
                            }
                        }
                    }else{                    
                        tmpi = intersect(m1,tmp);
                        if(tmpi[0]!=-1){
                            if(m1.rowlen>1&&m1.collen*m1.rowlen>m3.collen*m3.rowlen){
                                m3 = new Matrix(m1.rowstart,m1.colstart,m1.collen,m1.rowlen);
                            }
                            m1.tmpcollen = m1.collen;
                            m1.tmpcolstart = m1.colstart;
                            m1.colstart = tmpi[0];
                            m1.collen = tmpi[1];
                            m1.rowlen ++;
                            m1.endflag=false;
                            c2.removeElement(tmp);
                        }else{
                            m1.endflag=true;
                        }                    
                    }
                }
                if(m1.endflag){
                    if(m1.rowlen>1&&m1.collen*m1.rowlen>m2.collen*m2.rowlen){
                        m3 = m1;
                    }
                    c1.removeElement(m1);
                }
            }
            return m3;
        }
        
        public static int[] intersect(Matrix m1,Matrix m2){
            int[] a = new int[2];
            a[0]=-1;
            a[1]=-1;
            if(m1.colstart>=m2.colstart&&(m1.colstart+m1.collen)<=(m2.colstart+m2.collen)){
                a[0] = m1.colstart;
                a[1] = m1.collen;            
            }
            if(m1.colstart>=m2.colstart&&m1.colstart>=m2.colstart+m2.collen&&(m1.colstart+m1.collen)>=(m2.colstart+m2.collen)){
                if(a[1]>2){
                    a[0] = m1.colstart;
                    a[1] = m2.collen+m2.colstart-m1.colstart;
                }
            }
            if(m1.colstart<=m2.colstart&&(m1.colstart+m1.collen)>=(m2.colstart+m2.collen)){
                a[0] = m2.colstart;
                a[1] = m2.collen;
            }
            if(m1.colstart<=m2.colstart&&m2.colstart<=m1.colstart+m1.collen&&(m1.colstart+m1.collen)<=(m2.colstart+m2.collen)){
                if(a[1]>2){
                    a[0] = m2.colstart;
                    a[1] = m1.collen+m1.colstart-m2.colstart;
                }
            }
            return a;
        }
        
        public static int[] getBound(String str){
            int[] res = new int[str.length()];
            String[] tmp = str.split("1");
            int k=0;
            int count=0;
            for(int i=0;i<tmp.length;i++){
                k++; 
                if(!tmp[i].equals("")){                
                    if(!tmp[i].equals("0")){
                        res[count]=k;
                        res[count+1]=tmp[i].length();
                        count+=2;
                    }
                    k+=tmp[i].length();
                }
            }
            int[] newres = new int[count];
            for(int i=0;i<newres.length;i++){
                newres[i] = res[i];
            }
            return newres;
        }
        
        public static Vector makeNewMatrix(int[] bounds,int currow){
            Vector tmpV = new Vector();
            for(int i=0;i<bounds.length;i=i+2){//开始点和长度存在一起了
                tmpV.addElement(new Matrix(currow,bounds[i],bounds[i+1]));
            }
            return tmpV;
        }
        
        public static void main(String[] args){
            Vector collect = new Vector();
            Vector tmpCollect = new Vector();
            Vector tmpV = null;
            Matrix max = new Matrix(0,0,0,0);
            Matrix tmp = null;
            String[] news={"10101000010100010","10100011000101010","10100011000101010","10100000010100000","10100100010100100"};
            for(int i=0;i<news.length;i++){
                int[] tmpInt = getBound(news[i]);            
                tmpCollect = makeNewMatrix(tmpInt,i);
                if(collect.size()==0){
                    collect = tmpCollect;
                }else{
                    tmpV = new Vector();
                    for(int j=collect.size()-1;j>=0;j--){
                        tmp = (Matrix)collect.get(j);
                        max = joinMatrix(tmp,max,collect,tmpCollect,tmpV);
                    }
                    for(int j=0;j<tmpCollect.size();j++){
                        collect.addElement(tmpCollect.elementAt(j));
                    }                
                    for(int j=0;j<tmpV.size();j++){
                        collect.addElement(tmpV.elementAt(j));
                    }                
                    tmpV = null;
                    tmpCollect = null;
                }
            }
            
            for(int i=0;i<collect.size();i++){
                tmp = (Matrix)collect.get(i);            
                if(tmp.rowlen>1&&tmp.collen*tmp.rowlen>max.collen*max.rowlen){
                    max = tmp;
                }
            }
                   
            for(int i=0;i<news.length;i++){
                System.out.println("行:"+news[i]);
            }
            if(max==null){
                System.out.println("没能找到。");
            }else{            
                System.out.print("\n最大面积:"+max.rowlen*max.collen+"\n\n");
                for(int i=max.rowstart;i<max.rowstart+max.rowlen;i++){
                    for(int j=max.colstart;j<max.colstart+max.collen;j++){
                        System.out.print("("+(i+1)+","+j+")");
                    }            
                    System.out.print("\n");
                }
            }
        }
    }
      

  7.   

    Try this:class ArrayFinder {
      int[][] num;
      
      public ArrayFinder(int[][] num) {
        this.num = num;
      }
      public static void main(String[] args) {
        new ArrayFinder(new int[][]{
                        { 1, 0, 1, 0, 1}, 
                        { 1, 0, 0, 0, 0},
                        { 0, 0, 0, 0, 1},
                        { 1, 0, 0, 0, 0},
        }).find();
      }
      
      public void find() {
        int max = 0;
        int[] coor = null;
        for (int y = 0; y < num.length; y++) {
          for (int x = 0; x < num[y].length; x++) {
            if (num[y][x] != 0) continue;
            int[] new_coor = seek(x, y);
            if (max < area(new_coor)) {
              max = area(new_coor);
              coor = new_coor;
            }
          }
        }
        display(coor);
      }  private static int area(int[] c) {
        return (c[2] - c[0] + 1) * (c[3] - c[1] + 1);
      }  public int[] seek(int x0, int y0) {
        int yy = y0;
        int minWidth = num.length;
        for (int y = y0; y < num.length; y++) {
          if (num[y][x0] != 0)
            break;
          int width = getWidth(x0, y);
          minWidth = (width <= minWidth) ? width:minWidth;
          yy = y;
        }
        return new int[] { x0, y0, minWidth + x0 - 1, yy};
      }  private int getWidth(int x, int y) {
        int x0 = x;
        while (x < num[y].length - 1)
          if (num[y][++x] != 0)
            return x - x0;
        return x - x0 + 1;
      }  public static void display(int[] d) {
        System.out.println(
          "(" + d[0] + "," + d[1] + ")-(" + d[2] + "," + d[3] +
                         ")---Max Elements=" + area(d));
      }
    }
      

  8.   

    我的想法:
     初始条件:
     1:设方阵有J行,I列  算法:
     1:按行遍历(列类似);
         初始:i1=0;j1=0;  
         遍历:i1++; if(i1>I-1) {i1=0;j1++;}
         到第2步
     2:找到第一个0后,记下位置标记(i1,j1); 到第3步
     3:“斜下”走(i2=i1++;j2=j1++;); 到第4步
     4:若是零,判断当前位置(i2,j2)上方(行标i2,列标j2到j1)元素和左方元素(行标i2~i1,列标j2)是否均为零;
        若不是,到第6步,回到第一步; 若是到第5步
     5:若是继续斜下走(while( isRealBound(i1,j1,i2+1,j2+1)) {i2++;j2++} );
        直到不是时转到第6步; 
        //isRealBound:判断当前位置(i2+1,j2+1)上方(行标i2+1,列标j2+1到j1)元素和左方元素(行标i2+1到i1,列标j2+1)是否均为零
     6:若不是,记下位置标记(i2,j2);到第7步
        //到此基本可以实现最大正方形算法
     7:i2>i1? 若不是, i1++; if(i1>I-1) {i1=0;j1++;}回第一步遍历; 若是到第8步;
     
     8:(右端扩展) i3=i2;j3=j2; while( isRowBound(i1,j1,i3+1,j3+1)) {i3++;}
        扩展完后到第9步; 
         //isRowBound:判断当前位置(i3+1,j3+1)上方(行标i3+1,列标j3+1到j1)元素是否均为零
     9:i3>i2? 若是记下方阵(i1,j1,i3,j3),到第11步;若不是直接到第11步;
     11:(下端扩展) i4=i2;j4=j2; while( isColBound(i1,j1,i4+1,j4+1)) {j4++;}
        扩展完后到第12步; 
         //isColBound:判断当前位置(i4+1,j4+1)左方(行标i4+1到i1,列标j4+1)元素是否均为零
     12:i4>i2? 若是记下方阵(i1,j1,i4,j4),到第13步;若不是直接到第13步;
     13:i1=i3;回第一步遍历;
      

  9.   

    13:应该是i1++; if(i1>I-1) {i1=0;j1++;}回第一步遍历;
      

  10.   

    精简的C#版来了,可能算法不是最优的,但是非常简单using System;public class ScanBlock
    {
      private static int [,] map1 = 
        {
          {1,1,0,1,1},
          {0,0,0,0,1},
          {1,0,0,0,1},
          {1,0,1,0,1}
        };
      private static int [,] map2 =
        {
          {1,0,0,1,0},
          {1,0,0,1,0},
          {1,0,0,0,0},
          {1,0,0,1,0}
        };  
      private static int [,] map3 =
        {
          {1,1,0,1,1},
          {0,1,0,0,1},
          {1,0,1,0,1},
          {1,0,1,0,1}
        };
      private static int [,] map4 = 
        {
          {0,0,0,1,1},
          {0,0,1,0,1},
          {1,1,0,0,1},
          {1,0,0,0,1}
        };  private static int ScanLine(int [,] map, int line, int left)
      {
        for(int i = left; i < map.GetLength(1); i++)
        {
          if(map[line, i] != 0) return i - left;
        }
        return map.GetLength(1) - left;
      }  private static int ScanPoint(int [,] map,
        int top, int left, 
        ref int width, ref int height)
      {
        int stride = map.GetLength(1) + 1;
        int stride1 = 0;
        int area = 0;
        height = width = 0;
        for(int i = top; i < map.GetLength(0); i++)
        {
          stride1 = ScanLine(map, i, left);
          if(stride1 == 0) break;
          stride = Math.Min(stride, stride1);
          if(area < (i - top + 1) * stride)
          {
            width = stride;
            height = i - top + 1;
            area = width * height;
          }
        }
        return area;
      }  private static void Scan(int [,] map)
      {
        int mwidth = 0, mheight = 0;
        int mleft  = 0, mtop    = 0;
        int width  = 0, height  = 0;    for(int i  = 0; i < map.GetLength(0); i++)
        {
          for(int j = 0; j < map.GetLength(1); j++)
          {
            if(map[i,j] != 0) continue;
            int area = ScanPoint(map, i, j, ref width, ref height);
            if(area > mwidth * mheight)
            {
              mtop = i; mleft = j;
              mwidth = width; mheight = height;
            }
          }
        }
        Console.WriteLine("max area {0} * {1} = {2}, at point [{3},{4}]",
          mwidth, mheight, mwidth * mheight, mtop, mleft);
      }  public static void Main(string [] args)
      {
        Scan(map1);
        Scan(map2);
        Scan(map3);
        Scan(map4);
      }
    }
      

  11.   

    public class Matrix {
    final int FOUND = 0;
    final int MAXWIDTH = 10000;
    int width, high;

    public void find(int[][] m){
    int position[] = {0, 0, 0, 0};
    int maxStepPosition[] = {0, 0, 0, 0};
    int maxStep = 0;

    high = m.length;
    width = m[0].length;

    for (int i = 0; i < high; i++){
    for(int j = 0; j < width; j++){
    if (m[i][j] == FOUND){
    position[0] = i;
    position[1] = j;
    maxStep = maxStepPosition[2] * maxStepPosition[3];
    position = calculateStep(position, m);
    int step = position[2] * position[3];
    if(step > maxStep){
    for(int k = 0; k < maxStepPosition.length; k++){
    maxStepPosition[k] = position[k];
    }
    }
    }
    }
    }
    System.out.println("MaxStepPosition: (" + maxStepPosition[0] +
    "," + maxStepPosition[1] + ") steps = (" + 
    maxStepPosition[2] + "," + maxStepPosition[3] + ")");
    }

    private int[] calculateStep(int[] p, int[][] m){
    int steps[] = new int[high];
    for (int i = p[0]; i < high; i++){
    boolean end = false;
    for(int j = p[1]; j < width; j++){
    if (m[i][j] == FOUND){
    if(!end){
    steps[i - p[0]]++;
    }
    }
    else{
    end = true;
    }
    }
    // System.out.println("p(" + p[0] + "," + p[1] + ") " + (i - p[0]) +  ": " + steps[i - p[0]]);
    }
    return putMaxStep(p, steps);
    }

    private int[] putMaxStep(int[] p, int[] step){
    int[] maxSteps = {0, 0};
    int wStep = MAXWIDTH, hStep = 0, maxStep = 0;
    for (int i = 0; i < high; i++){
    wStep = wStep > step[i] ? step[i] : wStep;
    int steps = (i + 1) * wStep;
    if(steps > maxStep){
    maxStep = steps;
    maxSteps[0] = wStep;
    maxSteps[1] = i + 1;
    }
    // System.out.println("wStep:" + maxSteps[0] + " hStep:" + maxSteps[1]);
    }
    p[2] = maxSteps[0];
    p[3] = maxSteps[1];
    return p;
    } public static void main(String[] args){
    int[][] matrix = { {1,0,0,0,1},
    {1,0,0,1,0},
    {1,0,0,0,1},
    {1,1,0,0,1}};
    Matrix m = new Matrix();
    m.find(matrix);
    }
    }
      

  12.   

    我也来写一个。
    定义一个矩形,该矩形能够往右和往下长大。一个点也认为是一个矩形,该矩形的面积为1
    扫描点阵,碰到为零的点,将它定义成一个矩形,让它长大(方向是右和下交替进行,直到两个方向都不能长大);然后将它与已经有的矩形相比较,看是否相等或者是否相互包含,不等则加入已经找到的矩形中,如果相互包含,则去掉其中一个。
    扫描完毕后,在已经找到的矩形中,取面积比较大小,得到最大面积的那个矩形代码如下:
    import java.util.ArrayList;
    import java.util.List;public class RectangleCal {
      private static int[][] basePoints = {
          {1, 1, 0, 1, 1}
          , {0, 0, 0, 0, 1}
          , {1, 0, 0, 0, 1}
          , {1, 0, 1, 0, 1}
      };  public static void main(String[] args) {
        RectangleCal recCal = new RectangleCal();
        Rectangle rec = recCal.getMaxRec();
        System.out.println(rec);
    if(rec!=null)System.out.println(rec.getArea());
      }  public Rectangle getMaxRec() {
        List recList = new ArrayList();
        for (int i = 0; i < basePoints.length; i++) {
          for (int j = 0; j < basePoints[i].length; j++) {
            if (basePoints[i][j] == 0) {
              Rectangle rec = new Rectangle();
              rec.setTLeft(new Point(j, i));
              rec.setTRight(new Point(j, i));
              rec.setBLeft(new Point(j, i));
              rec.setBRight(new Point(j, i));
              rec.setMaxX(4);
              rec.setMaxY(3);
              rec.growth();          boolean flag = false;
              for (int k = 0; k < recList.size(); k++) {
                Rectangle rec1 = (Rectangle) recList.get(k);
                if (rec1.equals(rec)) {
                  flag = true;
                  break;
                }
                if (rec1.isInside(rec)) {
                  recList.remove(rec1);
                  break;
                }
                if (rec.isInside(rec1)) {
                  flag = true;
                  break;
                }
              }
              if (!flag) recList.add(rec);
            }
          }
        }
        System.out.println("×&Uuml;&sup1;&sup2;&Oacute;&ETH;&frac34;&Oslash;&ETH;&Icirc;&pound;&ordm;" + recList.size() + "&cedil;&ouml;");
        if (recList.size() == 0)return null;
        else {
          int pos = 0;
          for (int k = 0; k < recList.size(); k++) {
            Rectangle rec1 = (Rectangle) recList.get(k);
            Rectangle rec2 = (Rectangle) recList.get(pos);
            if (rec1.getArea() > rec2.getArea()) pos = k;
            rec1.print();
          }
          return (Rectangle) recList.get(pos);
        }
      }  class Rectangle {
        private Point tLeft;
        private Point tRight;
        private Point bLeft;
        private Point bRight;
        private int maxX;
        private int maxY;
        public int getMaxY() {
          return maxY;
        }    public int getMaxX() {
          return maxX;
        }    public RectangleCal.Point getBLeft() {
          return bLeft;
        }    public RectangleCal.Point getTRight() {
          return tRight;
        }    public RectangleCal.Point getTLeft() {
          return tLeft;
        }    public void setBRight(RectangleCal.Point bRight) {
          this.bRight = bRight;
        }    public void setBLeft(RectangleCal.Point bLeft) {
          this.bLeft = bLeft;
        }    public void setTRight(RectangleCal.Point tRight) {
          this.tRight = tRight;
        }    public void setTLeft(RectangleCal.Point tLeft) {
          this.tLeft = tLeft;
        }    public void setMaxY(int maxY) {
          this.maxY = maxY;
        }    public void setMaxX(int maxX) {
          this.maxX = maxX;
        }    public RectangleCal.Point getBRight() {
          return bRight;
        }    public int getArea() {
          int leng = Math.abs(this.getTLeft().getX() - this.getTRight().getX()) + 1;
          int width = Math.abs(this.getTLeft().getY() - this.getBLeft().getY()) + 1;
          return width * leng;
        }    /**
         * &ETH;&pound;&Ntilde;é&Aacute;&frac12;&cedil;&ouml;&frac34;&Oslash;&ETH;&Icirc;&Ecirc;&Ccedil;·&ntilde;&Iuml;à&Iacute;&not;
         * @param rec1 Rectangle
         * @return boolean
         */
        public boolean equals(Rectangle rec1) {
          if (rec1.getBLeft().equals(this.getBLeft())
              && rec1.getBRight().equals(this.getBRight())
              && rec1.getTRight().equals(this.getTRight())
              && rec1.getTLeft().equals(this.getTLeft()))
            return true;
          else return false;
        }    /**
         * &ETH;&pound;&Ntilde;é&Ograve;&raquo;&cedil;&ouml;&frac34;&Oslash;&ETH;&Icirc;&Ecirc;&Ccedil;·&ntilde;&Ocirc;&Uacute;&Aacute;í&Iacute;&acirc;&Ograve;&raquo;&cedil;&ouml;&frac34;&Oslash;&ETH;&Icirc;&Auml;&Uacute;
         * @param rec1 Rectangle
         * @return boolean
         */
        public boolean isInside(Rectangle rec1) {
          if (rec1.getBRight().getX() >= this.getBRight().getX()
              && rec1.getBRight().getY() >= this.getBRight().getY()
              && rec1.getTLeft().getX() <= this.getTLeft().getX()
              && rec1.getTLeft().getY() <= this.getTLeft().getY())
            return true;
          else return false;
        }    public void print() {
          System.out.println("(" + this.getTLeft().getY() + "," +
                             this.getTLeft().getX() + "),(" + this.getBRight().getY() +
                             "," + this.getBRight().getX() + ")");
        }    public void growth() {
          //&Iacute;ù&Ouml;&Uuml;&Icirc;§&sup3;¤&acute;ó
          boolean flag90 = check90();
          boolean flag180 = check180();
          if (this.getTLeft().getX() == 1 && this.getTLeft().getY() == 1)
            System.out.println(flag90 + "/" + flag180);
          if ( (!flag90) && (!flag180)) {
            return;
          }
          if (flag180) {
            growth180();
            return;
          }
          if (flag90) {
            growth90();
            return;
          }
        }
        /**
         * &Iacute;ù&Oacute;&Ograve;&sup3;¤&acute;ó
         */
        private void growth90() {
          boolean flag90 = check90();
          if (!flag90) {
            return;
          }
          if (flag90) {
            this.getTRight().setX(this.getTRight().getX() + 1);
            this.getBRight().setX(this.getBRight().getX() + 1);
            growth180();
            growth90();
            return;
          }
        }
        /**
         * &Iacute;ù&Iuml;&Acirc;&sup3;¤&acute;ó
         */
        public void growth180() {
          boolean flag180 = check180();
          if (!flag180) {
            return;
          }
          if (flag180) {
            this.getBLeft().setY(this.getBLeft().getY() + 1);
            this.getBRight().setY(this.getBRight().getY() + 1);
            growth90();
            growth180();
            return;
          }
        }
        /**
         * &ETH;&pound;&Ntilde;é&Auml;&Uuml;·&ntilde;&Iacute;ù&Iuml;&Acirc;&sup3;¤&acute;ó
         * @return boolean
         */
        private boolean check180() {
          //&Aring;&ETH;&para;&Iuml;180&para;&Egrave;·&frac12;&Iuml;ò&Eacute;&Iuml;&Ecirc;&Ccedil;·&ntilde;&Auml;&Uuml;&sup1;&raquo;&Ocirc;&ouml;&frac14;&Oacute;
          int y = this.getBLeft().getY() + 1;
          if (y > maxY)return false;
          int x1 = this.getBLeft().getX();
          int x2 = this.getBRight().getX();      for (int i = x1; i <= x2; i++) {
            if (RectangleCal.basePoints[y][i] == 1)return false;
          }
          return true;
        }
        /**
         * &ETH;&pound;&Ntilde;é&Auml;&Uuml;·&ntilde;&Iacute;ù&Oacute;&Ograve;&sup3;¤&acute;ó
         * @return boolean
         */
        private boolean check90() {
          //&Aring;&ETH;&para;&Iuml;90&para;&Egrave;·&frac12;&Iuml;ò&Eacute;&Iuml;&Ecirc;&Ccedil;·&ntilde;&Auml;&Uuml;&sup1;&raquo;&Ocirc;&ouml;&frac14;&Oacute;
          int x = this.getTRight().getX() + 1;
          if (x > maxX)return false;
          int y1 = this.getTRight().getY();
          int y2 = this.getBRight().getY();
          for (int i = y1; i <= y2; i++) {
            if (RectangleCal.basePoints[i][x] == 1)return false;
          }
          return true;
        }
      };
    }
      

  13.   

    今天换了个思路,呵呵,现在得计算次数大概是m*n的矩阵里面,计算次数大约为O(m*n).
    代码如下:
    /*
     * 创建日期 2005-4-21
     *
     * TODO 要更改此生成的文件的模板,请转至
     * 窗口 - 首选项 - Java - 代码样式 - 代码模板
     *//**
     * @author shenhw
     *
     * TODO 要更改此生成的类型注释的模板,请转至
     * 窗口 - 首选项 - Java - 代码样式 - 代码模板
     */
    public class Matrix {
        public int rowstart;
        public int rowlen;
        public int colstart;
        public int collen;
        public static long times;
        
        public Matrix(int rowstart,int rowlen,int colstart,int collen){
            this.rowstart = rowstart;
            this.rowlen = rowlen;
            this.colstart = colstart;
            this.collen = collen;        
        }
        
        public static byte[] concat(byte[] int1,byte[] int2){
            byte[] tmp = new byte[int1.length];
            for(int i=0;i<int1.length;i++){
                tmp[i]=(byte)(int1[i]|int2[i]);
                times++;
            }
            return tmp;
        }
        
        public static int[] getBound(byte[] bits){
            String a=new String(bits);
            char b= 1;
            String[] c = null;
            c = a.split(b+"");
            int[] res = new int[2];
            res[0]=0;
            res[1]=0;
            int k=0;
            times++;
            for(int i=0;i<c.length;i++){
                if(c[i].length()>res[1]){
                    res[0] = k;
                    res[1] = c[i].length();                
                }
                times++;
                k++;
                k+=c[i].length();
            }       
             
            return res;
        }
        
        public static void main(String[] args){
            int m = Integer.parseInt(args[0]);
            int n = Integer.parseInt(args[1]);
            byte[][] input= new byte[m][n];
            byte[] tmp = null;
            int maxC = 0;
            int[] smax = null;
            int inc=0;
            Matrix a = null;        
            for(int i=0;i<m;i++){
                for(int j=0;j<n;j++){
                    input[i][j] = (byte)Math.round((float)Math.random()*0.8);
                }
            }
            for(int i=0;i<m-1;i++){
                inc = 0;
                tmp = input[i];
                smax = getBound(tmp);
                while(smax[1]>1&&(i+inc<m-1)){
                    inc++;
                    tmp = concat(tmp,input[i+inc]);
                    smax = getBound(tmp);
                    if(smax[1]>1){
                        if(smax[1]*(inc+1)>maxC){
                            maxC = smax[1]*(inc+1);
                            a = new Matrix(i,inc+1,smax[0],smax[1]);
                        }
                    }
                }
            }
            for(int i=0;i<m;i++){
                System.out.print("\n行:");
                for(int j=0;j<n;j++){
                    System.out.print(input[i][j]);
                }
            }
            
            if(maxC==0){
                System.out.print("\n没找到矩形");            
            }else{
                System.out.print("\n找到的最大面积:"+maxC);
                for(int i=a.rowstart;i<a.rowstart+a.rowlen;i++){
                    System.out.print("\n");
                    for(int j=a.colstart;j<a.colstart+a.collen;j++){
                        System.out.print("("+(i+1)+","+(j+1)+")");
                    }
                }
            }
            System.out.print("\n计算次数:"+times);    
        }
    }
      

  14.   

    哈哈哈。
    又愁又长的来啦。
    --------------------------------------------------------------------------------import java.lang.String;class Point {    private int x = 0;
        private int y = 0; //点的(X,y)坐标;数组表示为:arr[y][x]    Point() {}
        Point(int pX, int pY){ setPoint(pX, pY); }
        Point(Point point){ setPoint(point); }
        public int getX(){ return x; }
        public int getY(){ return y; }
        public void setPoint(int pX, int pY) {
    x = pX;
    y = pY;
        }
        public void setPoint(Point point) {
    x = point.getX();
    y = point.getY();
        }    public Point right(){ return new Point((x+1),y); }
        public void right(int n){ x = x + n; }
        public Point down(){ return new Point(x,(y+1)); }
        public void down(int n){ y = y + n; }
        public Point rightdown(){ return new Point( (x+1), (y+1) ); }
        public Point newPointBy(int X,int Y){ return new  Point( (x+X), (y+Y) ); }
        public Point newPointBy(Point point){ return newPointBy( point.getX(), point.getY() ); }
    }class Rect {    private Point pStart; //矩形的左上坐标
        private Point pEnd; //矩形的右下坐标    Rect() {
    pStart = new Point();
    pEnd   = new Point();
        }
        Rect(int pX, int pY) {
    pStart = new Point(pX,pY);
    pEnd   = new Point(pX,pY);
        }
        Rect(int pSX, int pSY,int pEX, int pEY) {
    pStart = new Point(pSX,pSY);
    pEnd   = new Point(pEX,pEY);
        }
        Rect(Point pS, Point pE) {
    pStart = new Point(pS);
    pEnd   = new Point(pE);
        }    public Point getStartPoint(){ return pStart; }
        public Point getEndPoint(){ return pEnd; }
        public void setRectStart(Point point){ pStart.setPoint(point); }
        public void setRectStart(int pX,int pY){ pStart.setPoint(pX,pY); }
        public void setRectEnd(Point point){ pEnd.setPoint(point); }
        public void setRectEnd(int pX,int pY){ pEnd.setPoint(pX,pY); }
        public void setRect(Point pS, Point pE){
    pStart.setPoint(pS);
    pEnd.setPoint(pE);
        }    public int getAcre() {
    return 0;
        }
        public int getRound() {
    return 0;
        }}class Method {    private int[][] ary;
        private int X,Y;    //绑定Method的操作数组;
        public boolean arrBind(int[][] arrData) {
    if(arrData.length>=2) {
        if(arrData[1].length>=2) {
    ary = arrData;
    return true;
        }
    }
    showFaildString();
    ary = null;
    return false;
        }
        public boolean arrBind(int x, int y) { if( (x>20)||(y>20) ) {
        showFaildString();
        return false;
    }
    ary = new int[y][x];
    for(int i=0; i<y; i++) {
        for(int j=0; j<x; j++) {
    ary[i][j] = random_01();
        }
    }
    return true;
        }
        public void arrDisConnect() {
    ary = null;
        }    public Rect maxArea() { if(!checkBind()) return null;
    boolean bFound = false;
    Point pStart = new Point();
    Point pEnd;
    Rect rRetVal = new Rect(); for(int i=0; i<ary.length; i++) {
        for(int j=0; j<ary[i].length; j++) {
    //如果该点值为'0',生成最大矩形;
    if(ary[i][j]==0) {
        pStart.setPoint(j,i);
        pEnd = getMaxEndPoint(pStart);
        if(pEnd!=null) {
    rRetVal.setRect( pStart, pEnd );
    bFound = true;
        }
    }
        }
    }
    if(bFound)
        return rRetVal;
    else
        return null;
        }
        public void drawArea(Rect area) {
    if(!checkBind()) return;
    System.out.println("Start---------------------------------------------");
    for(int i=0; i<ary.length; i++) {
        System.out.print("  ");
        for(int j=0; j<ary[i].length; j++){
    if( (area.getStartPoint().getX()<=j)&&(j<=area.getEndPoint().getX())&&(area.getStartPoint().getY()<=i)&&(i<=area.getEndPoint().getY()) )
        System.out.print(" *");
    else
        System.out.print(" "+ary[i][j]);
        }
        System.out.println("");
    }
        }
        public void drawArea() {
    if(!checkBind()) return;
    System.out.println("Start---------------------------------------------");
    for(int i=0; i<ary.length; i++) {
        System.out.print("  ");
        for(int j=0; j<ary[i].length; j++){
    System.out.print(" "+ary[i][j]);
        }
        System.out.println("");
    }
        }
        public int getLastMaxAreaSize() {
    if(!checkBind()) return -1;
    return X*Y;
        }
        //形式成最大矩形 返回第1最大矩形面积终点坐标
        private Point getMaxEndPoint(Point pStart) {
    boolean bFound = false;
    if(!checkBind()) return null;
    if(!isZero(pStart)) return null;
    if(!isZero(pStart.right())) return null;
    if(!isZero(pStart.down())) return null;
    if(!isZero(pStart.rightdown())) return null; int x=0,y;
    do {
        x++;
        y=1;
        while((ary.length>(pStart.getY()+y+1))&&appendH(pStart,x,y)) {
    y++;
        }     if( (x+1)*(y+1)>(X+1)*(Y+1) ) {
    X = x;
    Y = y;
    bFound = true;
        }
    }while((ary[pStart.getY()].length>(pStart.getX()+x+1))&&appendH(pStart,x,1)); if(bFound)
        return pStart.newPointBy(X,Y);
    else
        return null;
        }
        //横向(右)追加矩形面积 成功返回true
        private boolean appendW(Point pThis, int X, int Y) {
    int xVal = pThis.getX()+X+1;
    for(int i=0; i<=Y; i++) {
        if(ary[pThis.getY()+i][xVal]==1)
    return false;
    }
    return true;
        }
        //纵向(下)追加矩形面积 成功返回true
        private boolean appendH(Point pThis, int X, int Y) {
    int yVal = pThis.getY()+Y+1;
    for(int i=0; i<=X; i++) {
        if(ary[yVal][pThis.getX()+i]==1)
    return false;
    }
    return true;
        }
        private boolean isZero(int pX,int pY){ return (ary[pY][pX]==0)?( (ary.length<=(pY+1))||(ary[pY].length<=(pX+1))?false:true ):false; }
        private boolean isZero(Point pStart){ return isZero(pStart.getX(),pStart.getY()); }
        private boolean checkBind() {
    if(ary==null) {
        showFaildString();
        return false;
    } return true;
        }
        private int random_01(){
    //return 1;
    return (Math.random()*10>7)?1:0;
        }
        private void showFaildString() {
    System.out.println("Method.ary is null;");
        }
    }
    public class JavaApp {    public static void main(String[] args) { int arr[][] = {
        {1, 1, 1, 1, 0, 0, 1},
        {1, 0, 0, 1, 0, 0, 1},
        {0, 0, 0, 0, 0, 0, 0},
        {1, 0, 1, 0, 0, 0, 1},
        {1, 0, 1, 0, 0, 0, 1},
        {1, 0, 0, 0, 0, 1, 1},
        {1, 0, 0, 0, 0, 1, 0},
    }; Rect myRect;
    Method meth = new Method();
    Point pStart, pEnd, pTemp; switch(args.length) {
        case 1:
    if(!meth.arrBind(Integer.parseInt(args[0]),Integer.parseInt(args[0]))) System.exit(0);
    break;
        case 2:
    if(!meth.arrBind(Integer.parseInt(args[0]),Integer.parseInt(args[1]))) System.exit(0);
    break;
        default:
    if(!meth.arrBind(arr)) System.exit(0);
    break;
    } meth.drawArea(); myRect = meth.maxArea();
    if(myRect==null) {
        System.out.println("not found;");
    }
    else 
        meth.drawArea(myRect); meth.arrDisConnect(); //System.gc();
        }
    }
      

  15.   

    D:\MyJava>javac JavaApp.javaD:\MyJava>java  JavaApp 9 8
    Start---------------------------------------------
       1 1 1 1 1 1 1 1 1
       1 1 1 1 1 1 1 1 1
       1 1 1 1 1 1 1 1 1
       1 1 1 1 1 1 1 1 1
       1 1 1 1 1 1 1 1 1
       1 1 1 1 1 1 1 1 1
       1 1 1 1 1 1 1 1 1
       1 1 1 1 1 1 1 1 1
    not found;D:\MyJava>javac JavaApp.javaD:\MyJava>java  JavaApp 9 8
    Start---------------------------------------------
       0 0 1 1 0 0 0 1 0
       1 1 0 0 1 0 1 0 0
       1 0 1 1 0 0 0 1 0
       1 0 0 0 0 1 0 0 0
       0 0 0 0 0 0 1 0 0
       0 0 0 0 1 1 0 1 0
       0 1 0 0 0 0 1 0 0
       0 0 0 0 0 0 0 0 0
    Start---------------------------------------------
       0 0 1 1 0 0 0 1 0
       1 1 0 0 1 0 1 0 0
       1 0 1 1 0 0 0 1 0
       1 0 0 0 0 1 0 0 0
       0 0 0 0 0 0 1 0 0
       0 0 * * * * * * *
       0 1 * * * * * * *
       0 0 * * * * * * *D:\MyJava>java  JavaApp 9 8
    Start---------------------------------------------
       0 0 1 1 0 1 0 1 1
       1 1 1 0 0 0 1 0 1
       0 0 1 0 0 1 0 0 0
       0 0 1 0 0 0 1 0 0
       0 0 1 0 0 0 1 1 0
       0 0 0 0 0 1 1 1 0
       0 1 0 0 1 0 0 0 1
       1 0 1 0 0 0 0 1 0
    Start---------------------------------------------
       0 0 1 1 0 1 0 1 1
       1 1 1 0 0 0 1 0 1
       0 0 1 0 0 1 0 0 0
       * * * * * 0 1 0 0
       * * * * * 0 1 1 0
       * * * * * 1 1 1 0
       0 1 0 0 1 0 0 0 1
       1 0 1 0 0 0 0 1 0D:\MyJava>java  JavaApp 9 8
    Start---------------------------------------------
       1 1 1 0 0 0 1 1 0
       0 0 0 0 0 1 0 0 1
       1 1 1 1 1 0 0 0 0
       0 1 1 0 0 0 0 1 0
       0 0 0 0 0 1 0 1 0
       0 1 1 1 0 0 0 1 1
       0 1 0 0 0 0 0 0 0
       0 0 1 0 0 0 0 1 1
    Start---------------------------------------------
       1 1 1 0 0 0 1 1 0
       0 0 0 0 0 1 0 0 1
       1 1 1 1 1 0 0 0 0
       0 1 1 0 0 0 0 1 0
       0 0 0 0 0 1 0 1 0
       0 1 1 1 * * * 1 1
       0 1 0 0 * * * 0 0
       0 0 1 0 * * * 1 1D:\MyJava>java  JavaApp 9 8
    Start---------------------------------------------
       0 1 0 1 0 0 1 0 0
       0 0 0 1 0 0 0 0 0
       0 0 0 0 0 1 0 1 0
       0 0 0 0 1 0 0 0 0
       1 1 0 0 1 1 0 0 0
       1 0 0 0 1 0 1 0 0
       0 0 1 0 1 0 0 1 0
       0 0 1 0 1 0 1 0 1
    Start---------------------------------------------
       0 1 0 1 0 0 1 0 0
       * * * * 0 0 0 0 0
       * * * * 0 1 0 1 0
       * * * * 1 0 0 0 0
       1 1 0 0 1 1 0 0 0
       1 0 0 0 1 0 1 0 0
       0 0 1 0 1 0 0 1 0
       0 0 1 0 1 0 1 0 1D:\MyJava>java  JavaApp 9 8
    Start---------------------------------------------
       0 0 0 0 0 0 1 0 0
       0 1 1 1 0 1 1 1 0
       0 0 0 0 0 0 0 0 0
       0 0 0 0 1 0 0 0 0
       0 1 0 0 0 1 1 0 0
       0 0 0 0 1 0 0 0 0
       0 0 0 0 0 0 0 1 0
       0 0 0 0 1 1 0 1 0
    Start---------------------------------------------
       0 0 0 0 0 0 1 0 0
       0 1 1 1 0 1 1 1 0
       0 0 0 0 0 0 0 0 0
       0 0 0 0 1 0 0 0 0
       0 1 * * * * * 0 0
       0 0 * * * * * 0 0
       0 0 * * * * * 1 0
       0 0 0 0 1 1 0 1 0D:\MyJava>java  JavaApp 9 8
    Start---------------------------------------------
       0 0 0 0 1 0 0 0 1
       0 0 0 0 1 1 0 0 0
       1 0 0 1 0 1 1 1 0
       0 0 0 0 1 1 0 1 0
       0 0 0 1 0 1 0 0 1
       0 1 0 0 0 0 0 1 0
       0 1 0 0 1 0 0 1 0
       0 0 0 0 1 0 1 0 0
    Start---------------------------------------------
       0 * * 0 1 0 0 0 1
       0 * * 0 1 1 0 0 0
       1 * * 1 0 1 1 1 0
       0 * * 0 1 1 0 1 0
       0 * * 1 0 1 0 0 1
       0 1 0 0 0 0 0 1 0
       0 1 0 0 1 0 0 1 0
       0 0 0 0 1 0 1 0 0D:\MyJava>java  JavaApp 9 8
    Start---------------------------------------------
       0 0 0 0 0 0 1 1 0
       1 1 1 0 1 0 0 0 0
       0 1 0 0 1 1 0 0 0
       1 1 0 1 1 0 0 1 0
       0 0 0 1 0 0 0 0 0
       0 1 0 0 0 1 0 0 0
       1 0 1 0 0 0 0 1 0
       0 0 0 0 0 0 0 0 1
    Start---------------------------------------------
       0 0 0 0 0 0 1 1 0
       1 1 1 0 1 0 0 0 0
       0 1 0 0 1 1 0 0 0
       1 1 0 1 1 0 0 1 0
       0 0 0 1 0 0 0 0 0
       0 1 0 * * * * * 0
       1 0 1 * * * * * 0
       0 0 0 * * * * * 1D:\MyJava>java  JavaApp 9 8
    Start---------------------------------------------
       0 0 1 1 0 0 0 0 1
       0 0 0 0 1 0 0 1 1
       0 1 0 0 0 0 0 0 0
       0 1 0 0 0 0 1 1 0
       0 0 0 1 0 1 0 0 0
       0 0 0 1 0 0 0 0 1
       0 0 1 0 0 0 1 1 1
       0 0 1 0 1 0 0 1 0
    Start---------------------------------------------
       0 0 1 1 0 * * * *
       0 0 0 0 1 * * * *
       0 1 0 0 0 * * * *
       0 1 0 0 0 0 1 1 0
       0 0 0 1 0 1 0 0 0
       0 0 0 1 0 0 0 0 1
       0 0 1 0 0 0 1 1 1
       0 0 1 0 1 0 0 1 0D:\MyJava>java  JavaApp 9 12
    Start---------------------------------------------
       0 0 0 0 0 1 0 0 1
       0 1 1 1 0 0 0 0 0
       0 0 0 1 1 1 1 1 0
       0 0 0 0 1 1 0 1 0
       0 1 0 1 0 1 1 0 1
       0 0 0 0 1 0 0 0 0
       0 0 0 1 0 0 0 0 1
       0 0 1 0 0 1 1 0 0
       1 0 0 1 0 0 0 1 1
       0 0 0 0 0 0 0 0 0
       0 0 1 1 0 0 0 0 0
       1 1 1 0 0 0 0 0 0
    Start---------------------------------------------
       0 0 0 0 0 1 0 0 1
       0 1 1 1 0 0 0 0 0
       0 0 0 1 1 1 1 1 0
       0 0 0 0 1 1 0 1 0
       0 1 0 1 0 1 1 0 1
       0 0 0 0 1 0 0 0 0
       0 0 0 1 0 0 0 0 1
       0 0 1 0 0 1 1 0 0
       1 0 0 1 * * * * *
       0 0 0 0 * * * * *
       0 0 1 1 * * * * *
       1 1 1 0 * * * * *D:\MyJava>java  JavaApp 9 12
    Start---------------------------------------------
       1 1 0 0 1 0 1 1 1
       0 0 0 1 0 0 0 1 0
       1 1 0 1 0 1 0 1 1
       0 0 0 0 0 0 0 0 0
       1 0 0 0 1 0 1 0 0
       0 0 1 1 0 1 0 1 0
       0 0 1 1 0 1 0 1 0
       0 1 0 0 0 1 0 0 1
       1 1 0 1 1 0 0 0 1
       1 1 1 0 0 1 0 0 0
       0 0 1 0 1 1 0 0 0
       0 0 0 0 1 0 1 0 1
    Start---------------------------------------------
       1 1 0 0 1 0 1 1 1
       0 0 0 1 0 0 0 1 0
       1 1 0 1 0 1 0 1 1
       0 0 0 0 0 0 0 0 0
       1 0 0 0 1 0 1 0 0
       0 0 1 1 0 1 0 1 0
       0 0 1 1 0 1 0 1 0
       0 1 0 0 0 1 * * *
       1 1 0 1 1 0 * * *
       1 1 1 0 0 1 * * *
       0 0 1 0 1 1 * * *
       0 0 0 0 1 0 1 0 1D:\MyJava>java  JavaApp 9 12
    Start---------------------------------------------
       1 0 1 0 0 0 0 0 0
       1 0 0 0 0 0 1 1 0
       1 0 0 0 1 0 1 0 0
       0 1 0 0 1 0 0 0 1
       0 1 0 0 1 0 0 0 0
       0 0 0 1 0 0 0 1 0
       1 0 0 0 0 1 0 0 1
       1 0 0 1 0 0 1 0 1
       0 0 0 0 0 0 0 0 0
       0 0 0 0 0 0 0 0 0
       1 0 1 1 0 0 0 0 0
       0 0 1 0 1 1 0 0 1
    Start---------------------------------------------
       1 0 1 0 0 0 0 0 0
       1 0 0 0 0 0 1 1 0
       1 0 0 0 1 0 1 0 0
       0 1 0 0 1 0 0 0 1
       0 1 0 0 1 0 0 0 0
       0 0 0 1 0 0 0 1 0
       1 * * * * * * * *
       1 * * * * * * * *
       0 * * * * * * * *
       0 * * * * * * * *
       1 0 1 1 0 0 0 0 0
       0 0 1 0 1 1 0 0 1D:\MyJava>java  JavaApp 9 12
    Start---------------------------------------------
       0 0 0 1 1 0 1 1 0
       1 0 0 0 0 0 0 1 1
       0 1 0 0 0 1 0 0 0
       1 1 1 1 0 0 0 0 0
       0 0 0 0 1 0 0 0 0
       0 1 1 0 1 0 1 1 0
       0 0 0 0 1 1 1 0 0
       0 1 0 1 0 0 0 1 1
       1 0 0 1 0 0 0 1 0
       1 0 0 1 1 0 1 1 0
       0 1 0 1 1 0 0 1 0
       0 0 1 0 0 0 0 0 1
    Start---------------------------------------------
       0 0 0 1 1 0 1 1 0
       1 0 0 0 0 0 0 1 1
       0 1 0 0 0 1 * * *
       1 1 1 1 0 0 * * *
       0 0 0 0 1 0 * * *
       0 1 1 0 1 0 1 1 0
       0 0 0 0 1 1 1 0 0
       0 1 0 1 0 0 0 1 1
       1 0 0 1 0 0 0 1 0
       1 0 0 1 1 0 1 1 0
       0 1 0 1 1 0 0 1 0
       0 0 1 0 0 0 0 0 1D:\MyJava>
      

  16.   

    错了。不好意思。。改:
    ===============================================================import java.lang.String;class Point {    private int x = 0;
        private int y = 0; //点的(X,y)坐标;数组表示为:arr[y][x]    Point() {}
        Point(int pX, int pY){ setPoint(pX, pY); }
        Point(Point point){ setPoint(point); }
        public int getX(){ return x; }
        public int getY(){ return y; }
        public void setPoint(int pX, int pY) {
    x = pX;
    y = pY;
        }
        public void setPoint(Point point) {
    x = point.getX();
    y = point.getY();
        }    public Point right(){ return new Point((x+1),y); }
        public void right(int n){ x = x + n; }
        public Point down(){ return new Point(x,(y+1)); }
        public void down(int n){ y = y + n; }
        public Point rightdown(){ return new Point( (x+1), (y+1) ); }
        public Point newPointBy(int X,int Y){ return new  Point( (x+X), (y+Y) ); }
        public Point newPointBy(Point point){ return newPointBy( point.getX(), point.getY() ); }
    }class Rect {    private Point pStart; //矩形的左上坐标
        private Point pEnd; //矩形的右下坐标    Rect() {
    pStart = new Point();
    pEnd   = new Point();
        }
        Rect(int pX, int pY) {
    pStart = new Point(pX,pY);
    pEnd   = new Point(pX,pY);
        }
        Rect(int pSX, int pSY,int pEX, int pEY) {
    pStart = new Point(pSX,pSY);
    pEnd   = new Point(pEX,pEY);
        }
        Rect(Point pS, Point pE) {
    pStart = new Point(pS);
    pEnd   = new Point(pE);
        }    public Point getStartPoint(){ return pStart; }
        public Point getEndPoint(){ return pEnd; }
        public void setRectStart(Point point){ pStart.setPoint(point); }
        public void setRectStart(int pX,int pY){ pStart.setPoint(pX,pY); }
        public void setRectEnd(Point point){ pEnd.setPoint(point); }
        public void setRectEnd(int pX,int pY){ pEnd.setPoint(pX,pY); }
        public void setRect(Point pS, Point pE){
    pStart.setPoint(pS);
    pEnd.setPoint(pE);
        }    public int getAcre() {
    return 0;
        }
        public int getRound() {
    return 0;
        }}class Method {    private int[][] ary;
        private int X,Y;    //绑定Method的操作数组;
        public boolean arrBind(int[][] arrData) {
    if(arrData.length>=2) {
        if(arrData[1].length>=2) {
    ary = arrData;
    return true;
        }
    }
    showFaildString();
    ary = null;
    return false;
        }
        public boolean arrBind(int x, int y) { if( (x>20)||(y>20) ) {
        showFaildString();
        return false;
    }
    ary = new int[y][x];
    for(int i=0; i<y; i++) {
        for(int j=0; j<x; j++) {
    ary[i][j] = random_01();
        }
    }
    return true;
        }
        public void arrDisConnect() {
    ary = null;
        }    public Rect maxArea() { if(!checkBind()) return null;
    boolean bFound = false;
    Point pStart = new Point();
    Point pEnd;
    Rect rRetVal = new Rect(); for(int i=0; i<ary.length; i++) {
        for(int j=0; j<ary[i].length; j++) {
    //如果该点值为'0',生成最大矩形;
    if(ary[i][j]==0) {
        pStart.setPoint(j,i);
        pEnd = getMaxEndPoint(pStart);
        if(pEnd!=null) {
    rRetVal.setRect( pStart, pEnd );
    bFound = true;
        }
    }
        }
    }
    if(bFound)
        return rRetVal;
    else
        return null;
        }
        public void drawArea(Rect area) {
    if(!checkBind()) return;
    System.out.println("Start---------------------------------------------");
    for(int i=0; i<ary.length; i++) {
        System.out.print("  ");
        for(int j=0; j<ary[i].length; j++){
    if( (area.getStartPoint().getX()<=j)&&(j<=area.getEndPoint().getX())&&(area.getStartPoint().getY()<=i)&&(i<=area.getEndPoint().getY()) )
        System.out.print(" *");
    else
        System.out.print(" "+ary[i][j]);
        }
        System.out.println("");
    }
        }
        public void drawArea() {
    if(!checkBind()) return;
    System.out.println("Start---------------------------------------------");
    for(int i=0; i<ary.length; i++) {
        System.out.print("  ");
        for(int j=0; j<ary[i].length; j++){
    System.out.print(" "+ary[i][j]);
        }
        System.out.println("");
    }
        }
        public int getLastMaxAreaSize() {
    if(!checkBind()) return -1;
    return X*Y;
        }
        //形式成最大矩形 返回第1最大矩形面积终点坐标
        private Point getMaxEndPoint(Point pStart) {
    boolean bFound = false;
    if(!checkBind()) return null;
    if(!isValidStart(pStart)) return null;
    if(!isZero(pStart.right())) return null;
    if(!isZero(pStart.down())) return null;
    if(!isZero(pStart.rightdown())) return null; int x=0,y;
    do {
        x++;
        y=1;
        while((ary.length>(pStart.getY()+y+1))&&appendH(pStart,x,y)) {
    y++;
        }     if( (x+1)*(y+1)>(X+1)*(Y+1) ) {
    X = x;
    Y = y;
    bFound = true;
        }
    }while((ary[pStart.getY()].length>(pStart.getX()+x+1))&&appendW(pStart,x,1)); if(bFound)
        return pStart.newPointBy(X,Y);
    else
        return null;
        }
        //横向(右)追加矩形面积 成功返回true
        private boolean appendW(Point pThis, int X, int Y) {
    int xVal = pThis.getX()+X+1;
    for(int i=0; i<=Y; i++) {
        if(ary[pThis.getY()+i][xVal]==1)
    return false;
    }
    return true;
        }
        //纵向(下)追加矩形面积 成功返回true
        private boolean appendH(Point pThis, int X, int Y) {
    int yVal = pThis.getY()+Y+1;
    for(int i=0; i<=X; i++) {
        if(ary[yVal][pThis.getX()+i]==1)
    return false;
    }
    return true;
        }
        private boolean isZero(int pX,int pY){ return (ary[pY][pX]==0)?true:false; }
        private boolean isZero(Point pStart){ return isZero(pStart.getX(),pStart.getY()); }
        private boolean isValidStart(int pX, int pY){ return isZero(pX,pY)?( (ary.length<=(pY+1))||(ary[pY].length<=(pX+1))?false:true ):false; }
        private boolean isValidStart(Point pStart){ return isValidStart(pStart.getX(),pStart.getY()); }
        private boolean checkBind() {
    if(ary==null) {
        showFaildString();
        return false;
    } return true;
        }
        private int random_01(){
    //return 1;
    return (Math.random()*10>7)?1:0;
        }
        private void showFaildString() {
    System.out.println("Method.ary is null;");
        }
    }
    public class JavaApp {    public static void main(String[] args) { int arr[][] = {
        {1, 1, 1, 1, 0, 0, 1},
        {1, 0, 0, 1, 0, 0, 1},
        {0, 0, 0, 0, 0, 0, 0},
        {1, 0, 1, 0, 1, 0, 1},
        {1, 0, 1, 0, 0, 1, 1},
        {1, 0, 0, 0, 0, 1, 1},
        {1, 0, 0, 0, 0, 1, 0},
    }; Rect myRect;
    Method meth = new Method();
    Point pStart, pEnd, pTemp; switch(args.length) {
        case 1:
    if(!meth.arrBind(Integer.parseInt(args[0]),Integer.parseInt(args[0]))) System.exit(0);
    break;
        case 2:
    if(!meth.arrBind(Integer.parseInt(args[0]),Integer.parseInt(args[1]))) System.exit(0);
    break;
        default:
    if(!meth.arrBind(arr)) System.exit(0);
    break;
    } meth.drawArea(); myRect = meth.maxArea();
    if(myRect==null) {
        System.out.println("not found;");
    }
    else 
        meth.drawArea(myRect); meth.arrDisConnect(); //System.gc();
        }
    }
      

  17.   

    to: hldc(胡乱打造)  可以的啊?D:\MyJava>javac JavaApp.javaD:\MyJava>java  JavaApp
    Start---------------------------------------------
       1 0 0 0 1
       1 0 1 0 1
       1 0 0 0 1
    not found;D:\MyJava>