62,635
社区成员




package test;
import java.util.ArrayList;
import java.util.List;
class pa{
public pa(int x,int y) {
this.y=y;
this.x=x;
}
public int x;
public int y;
}
public class StudentDamo{
static int max=0;
public static void main(String[] args) throws Exception{
char [][]ok=new char[3][3];
ok[0]=new char[]{'*','*','*','.','.'};
ok[1]=new char[]{'*','*','*','.','*'};
ok[2]=new char[]{'*','*','*','*','*'};
searchX(ok,0,0,0);
System.out.println(max);
}
public static void searchX(char[][]arr,int emrow,int emclo,int size) {
if(emrow>=arr.length) {//防止行过界
max=Math.max(max, size);
return ;
}
for (int i = emrow; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
if(i==emrow&&j<emclo) continue;
if(arr[i][j]=='.') {
max=Math.max(max, size+1);
List<pa> list=search(arr,i,j);
if(j==arr[0].length-1)//当前是最后一个就从头开始
searchX(arr,i+1,0,size+1);
else
searchX(arr,i,j+1,size+1);
for (pa pa : list) {
arr[pa.x][pa.y]='.';//恢复原来的状态
}
}
}
}
}
//返回我需要重置的点
public static List<pa> search(char[][]arr,int emrow,int emclo) {
List<pa> list=new ArrayList<pa>();
//只用判断下和右 我是一边过的 没有考虑最优解
if(emrow==arr.length-1&&emclo==arr[0].length-1) //右下角 不用管
return list;
if(emrow==arr.length-1) {//是最后一行把 右面的 人 kill 了
if(arr[emrow][emclo+1]=='.')
list.add(new pa(emrow, emclo+1));
arr[emrow][emclo+1]='*';
} else if(emclo==arr[0].length-1) {//同理 最后一列 把下面的kill
if(arr[emrow+1][emclo]=='.')
list.add(new pa(emrow+1, emclo));
arr[emrow+1][emclo]='*';
} else {
if(arr[emrow+1][emclo]=='.')
list.add(new pa(emrow+1, emclo));
if(arr[emrow][emclo+1]=='.')
list.add(new pa(emrow, emclo+1));
arr[emrow][emclo+1]='*';//同上
arr[emrow+1][emclo]='*';
}
return list;
}
}
---所有排列方法---
. * . * . * . *
* . * . * . * .
. * . * . * . *
* . * . * . * .
. * . * . * . *
* . * . * . * .
. * . * . * . *
* . * . * . * .
------32------
* . * . * . * .
. * . * . * . *
* . * . * . * .
. * . * . * . *
* . * . * . * .
. * . * . * . *
* . * . * . * .
. * . * . * . *
------32------
最大可用位置数:32
8*8矩阵64个可用位置总执行时间:576084毫秒
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
public class Demo {
static int maxCon = 0;// 统计最大可用位置数
public static void main(String[] args) {
char[][] ok = new char[8][8];
ok[0] = new char[] { '.', '.', '.', '.', '.', '*', '.', '.' };
ok[1] = new char[] { '.', '.', '.', '.', '.', '.', '.', '.' };
ok[2] = new char[] { '.', '*', '.', '.', '.', '.', '*', '.' };
ok[3] = new char[] { '.', '.', '.', '.', '.', '*', '.', '.' };
ok[4] = new char[] { '.', '.', '*', '.', '.', '*', '.', '.' };
ok[5] = new char[] { '.', '.', '.', '.', '.', '.', '*', '.' };
ok[6] = new char[] { '*', '.', '.', '*', '.', '.', '.', '.' };
ok[7] = new char[] { '.', '.', '.', '.', '.', '.', '.', '.' };
long start = new Date().getTime();
search(ok);
System.out.println("最大可用位置数:" + maxCon);
System.out.println("8*8矩阵64个可用位置总执行时间:" + (new Date().getTime() - start) + "毫秒");
}
public static void search(char[][] arr) {
// 第一轮计算
List<char[][]> listA = new ArrayList<>();
search(reverseArray(arr), listA);
// 第二轮计算
List<char[][]> listB = new ArrayList<>();
maxCon = 0;// 最大可用位置数置0
for (int i = 0; i < listA.size(); i++) {
search(reverseArray(listA.get(i)), listB);
}
printList(listB);// 打印,如果不需要打印,可去掉
}
public static void printList(List<char[][]> list) {
// 打印所有位置法
System.out.println("---所有排列方法---");
for (int s = 0; s < list.size(); s++) {
for (int i = 0; i < list.get(s).length; i++) {
for (int j = 0; j < list.get(s)[i].length; j++) {
System.out.print(list.get(s)[i][j] + " ");
}
System.out.println();
}
System.out.println("------" + maxCon + "------");
}
}
public static void search(char[][] arr, List<char[][]> list) {
int[] index = side(arr);
if (index[0] == -1) {
int con = 0;// 统计可用位置数
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (arr[i][j] == '.') {
con++;
}
}
}
if (maxCon < con) {
list.clear();
maxCon = con;
list.add(arr);
} else if (maxCon == con) {
list.add(arr);
}
} else {
// 复制数组
char[][] arrL = new char[arr.length][];
char[][] arrR = new char[arr.length][];
for (int i = 0; i < arrL.length; i++) {
arrL[i] = Arrays.copyOf(arr[i], arr[i].length);
arrR[i] = Arrays.copyOf(arr[i], arr[i].length);
}
// 去掉右边位置递归方法
arrL[index[0]][index[1] + 1] = '*';
search(arrL, list);
// 去掉左边位置递归方法
arrR[index[0]][index[1]] = '*';
if (index[1] + 2 < arrR[index[0]].length) {
arrR[index[0]][index[1] + 2] = '*';
}
search(arrR, list);
}
}
// 数组翻转
public static char[][] reverseArray(char[][] arr) {
int maxLength = 0;
for (int i = 0; i < arr.length; i++) {
if (maxLength < arr[i].length) {
maxLength = arr[i].length;
}
}
char[][] arrReverse = new char[maxLength][arr.length];
for (int i = 0; i < arrReverse.length; i++) {
for (int j = 0; j < arrReverse[i].length; j++) {
if (i < arr[j].length) {
arrReverse[i][j] = arr[j][i];
} else {
arrReverse[i][j] = '*';
}
}
}
return arrReverse;
}
// 判断是否有左右相邻可用位置并返回索引
public static int[] side(char[][] arr) {
int[] out = { -1, -1 };// -1为没有相邻可用位置
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (arr[i][j] == '.') {// 判断该位置是否可用
if (out[0] == -1 && j + 1 < arr[i].length && arr[i][j + 1] == '.') {
out[0] = i;// 获取第一个有相邻位置的Y索引
out[1] = j;// 获取第一个有相邻位置的X索引
}
}
}
}
return out;
}
}
以8*8矩阵为例:
ok[0] = new char[] { '.', '.', '.', '.', '.', '*', '.', '.' };
ok[1] = new char[] { '.', '.', '.', '.', '.', '.', '.', '.' };
ok[2] = new char[] { '.', '*', '.', '.', '.', '.', '*', '.' };
ok[3] = new char[] { '.', '.', '.', '.', '.', '*', '.', '.' };
ok[4] = new char[] { '.', '.', '*', '.', '.', '*', '.', '.' };
ok[5] = new char[] { '.', '.', '.', '.', '.', '.', '*', '.' };
ok[6] = new char[] { '*', '.', '.', '*', '.', '.', '.', '.' };
ok[7] = new char[] { '.', '.', '.', '.', '.', '.', '.', '.' };
两次运行结果:
---所有排列方法---
. * . * . * . *
* . * . * . * .
. * . * . * * *
* . * . * * * .
. * * * . * . *
* . * . * . * .
* * * * . * . *
. * . * * . * .
------27------
. * . * . * . *
* . * . * . * .
. * . * . * * *
* . * . * * * .
. * * * . * . *
* . * . * . * .
* * * * . * . *
. * * . * . * .
------27------
. * . * . * . *
* . * . * . * .
. * . * . * * *
* . * . * * * .
. * * * . * . *
* . * . * . * .
* * * * . * . *
* . * . * . * .
------27------
最大可用位置数:27
8*8矩阵64个可用位置总执行时间:24581毫秒
第二次:8*8矩阵64个可用位置总执行时间:25100毫秒import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
public class Demo {
static int maxCon = 0;// 统计最大可用位置数
public static void main(String[] args) {
char[][] ok = new char[8][7];
ok[0] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[1] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[2] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[3] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[4] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[5] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[6] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[7] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
long start = new Date().getTime();
search(ok);
System.out.println("最大可用位置数:" + maxCon);
System.out.println("8*7矩阵56个可用位置总执行时间:" + (new Date().getTime() - start) + "毫秒");
}
public static void search(char[][] arr) {
List<char[][]> listA = new ArrayList<>();
search(reverseArray(arr), listA);
List<char[][]> listB = new ArrayList<>();
for (int i = 0; i < listA.size(); i++) {
search(reverseArray(listA.get(i)), listB);
}
printList(listB);// 打印,如果不需要打印,可去掉
}
public static void printList(List<char[][]> list) {
// 打印所有位置法
System.out.println("---所有排列方法---");
for (int s = 0; s < list.size(); s++) {
for (int i = 0; i < list.get(s).length; i++) {
for (int j = 0; j < list.get(s)[i].length; j++) {
System.out.print(list.get(s)[i][j] + " ");
}
System.out.println();
}
System.out.println("------" + maxCon + "------");
}
}
public static void search(char[][] arr, List<char[][]> list) {
int[] index = side(arr);
if (index[0] == -1) {
int con = 0;// 统计最大可用位置数
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (arr[i][j] == '.') {
con++;
}
}
}
if (maxCon > con) {
return;
} else if (maxCon < con) {
list.clear();
maxCon = con;
}
list.add(arr);
} else {
// 复制数组
char[][] arrL = new char[arr.length][];
char[][] arrR = new char[arr.length][];
for (int i = 0; i < arrL.length; i++) {
arrL[i] = Arrays.copyOf(arr[i], arr[i].length);
arrR[i] = Arrays.copyOf(arr[i], arr[i].length);
}
// 去掉右边位置递归方法
arrL[index[0]][index[1] + 1] = '*';
search(arrL, list);
// 去掉左边位置递归方法
arrR[index[0]][index[1]] = '*';
if (index[1] + 2 < arrR[index[0]].length) {
arrR[index[0]][index[1] + 2] = '*';
}
search(arrR, list);
}
}
// 数组翻转
public static char[][] reverseArray(char[][] arr) {
int maxLength = 0;
for (int i = 0; i < arr.length; i++) {
if (maxLength < arr[i].length) {
maxLength = arr[i].length;
}
}
char[][] arrReverse = new char[maxLength][arr.length];
for (int i = 0; i < arrReverse.length; i++) {
for (int j = 0; j < arrReverse[i].length; j++) {
if (i < arr[j].length) {
arrReverse[i][j] = arr[j][i];
} else {
arrReverse[i][j] = '*';
}
}
}
return arrReverse;
}
// 判断是否有左右相邻可用位置并返回索引
public static int[] side(char[][] arr) {
int[] out = { -1, -1 };// -1为没有相邻可用位置
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (arr[i][j] == '.') {// 判断该位置是否可用
if (out[0] == -1 && j + 1 < arr[i].length && arr[i][j + 1] == '.') {
out[0] = i;// 获取第一个有相邻位置的Y索引
out[1] = j;// 获取第一个有相邻位置的X索引
}
}
}
}
return out;
}
}
以上代码以“8*7矩阵56个可用位置”为例运行了一下:
char[][] ok = new char[8][7];
ok[0] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[1] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[2] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[3] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[4] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[5] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[6] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
ok[7] = new char[] { '.', '.', '.', '.', '.', '.', '.' };
运行结果为:
---所有排列方法---
. * . * . * .
* . * . * . *
. * . * . * .
* . * . * . *
. * . * . * .
* . * . * . *
. * . * . * .
* . * . * . *
------28------
* . * . * . *
. * . * . * .
* . * . * . *
. * . * . * .
* . * . * . *
. * . * . * .
* . * . * . *
. * . * . * .
------28------
最大可用位置数:28
8*7矩阵56个可用位置总执行时间:41547毫秒
你的应该完全无法运行了char[][] ok = new char[6][6];
ok[0]=new char[]{'.','.','*','*','.','*'};
ok[1]=new char[]{'.','.','.','.','.','.'};
ok[2]=new char[]{'.','.','*','*','.','*'};
ok[3]=new char[]{'.','.','*','*','.','*'};
ok[4]=new char[]{'.','.','.','.','.','.'};
ok[5]=new char[]{'.','.','*','*','.','*'};
你的运行后过一会才会出来溢出异常,
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.grow(Unknown Source)
at java.util.ArrayList.ensureExplicitCapacity(Unknown Source)
at java.util.ArrayList.ensureCapacityInternal(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at Demo1.allsub(Demo1.java:58)
at Demo1.main(Demo1.java:25)
而我的基本是秒完,当然,矩阵再大点我的也会等很久,再再高点我的也好像会溢出import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Demo {
public static void main(String[] args) {
char[][] ok = new char[3][3];
ok[0] = new char[] { '*', '.', '*', '.', '.' };
ok[1] = new char[] { '.', '.', '*', '.', '*' };
ok[2] = new char[] { '*', '*', '*', '*', '*' };
System.out.println(search(ok));
}
public static int search(char[][] arr) {
List<char[][]> list = new ArrayList<>();
search(reverseArray(arr), list);
int s = list.size();
for (int i = 0; i < s; i++) {
search(reverseArray(list.get(0)), list);
list.remove(0);
}
int maxCon = 0;// 统计最大可用位置数
for (s = 0; s < list.size(); s++) {
int con = 0;// 统计最大可用位置数
for (int i = 0; i < list.get(s).length; i++) {
for (int j = 0; j < list.get(s)[i].length; j++) {
if (list.get(s)[i][j] == '.') {
con++;
}
}
}
if (maxCon < con) {
maxCon = con;
for (int i = 0; i < s; i++) {
list.remove(0);
}
s = 0;
} else if (maxCon > con) {
list.remove(s);
s--;
}
}
printList(list);// 打印,如果不需要打印,可去掉
return maxCon;
}
public static void printList(List<char[][]> list) {
// 打印所有位置法
for (int s = 0; s < list.size(); s++) {
int con = 0;
for (int i = 0; i < list.get(s).length; i++) {
for (int j = 0; j < list.get(s)[i].length; j++) {
System.out.print(list.get(s)[i][j] + " ");
if (list.get(s)[i][j] == '.') {
con++;
}
}
System.out.println();
}
System.out.println("----------");
}
}
public static void search(char[][] arr, List<char[][]> list) {
int[] index = side(arr);
if (index[0] == -1) {
list.add(arr);
} else {
// 复制数组
char[][] arrL = new char[arr.length][];
char[][] arrR = new char[arr.length][];
for (int i = 0; i < arrL.length; i++) {
arrL[i] = Arrays.copyOf(arr[i], arr[i].length);
arrR[i] = Arrays.copyOf(arr[i], arr[i].length);
}
// 去掉右边位置递归方法
arrL[index[0]][index[1] + 1] = '*';
search(arrL, list);
// 去掉左边位置递归方法
arrR[index[0]][index[1]] = '*';
if (index[1] + 2 < arrR[index[0]].length) {
arrR[index[0]][index[1] + 2] = '*';
}
search(arrR, list);
}
}
// 数组翻转
public static char[][] reverseArray(char[][] arr) {
int maxLength = 0;
for (int i = 0; i < arr.length; i++) {
if (maxLength < arr[i].length) {
maxLength = arr[i].length;
}
}
char[][] arrReverse = new char[maxLength][arr.length];
for (int i = 0; i < arrReverse.length; i++) {
for (int j = 0; j < arrReverse[i].length; j++) {
if (i < arr[j].length) {
arrReverse[i][j] = arr[j][i];
} else {
arrReverse[i][j] = '*';
}
}
}
return arrReverse;
}
// 判断是否有左右相邻可用位置并返回索引
public static int[] side(char[][] arr) {
int[] out = { -1, -1 };// -1为没有相邻可用位置
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (arr[i][j] == '.') {// 判断该位置是否可用
if (out[0] == -1 && j + 1 < arr[i].length && arr[i][j + 1] == '.') {
out[0] = i;// 获取第一个有相邻位置的Y索引
out[1] = j;// 获取第一个有相邻位置的X索引
}
}
}
}
return out;
}
}
public class Test8 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int max=0;
char[][] c= {{'*','.','*','*','.'},{'*','.','*','*','*'},{'*','.','*','*','.'} } ;
//将所有可以做人的位子放入list中
List<Position> list=new ArrayList<Position>();
for (int i=0;i<c.length;i++) {
for(int j=0;j<c[0].length;j++) {
if(c[i][j]=='.') {
list.add(new Position(i, j));
}
}
}
//取该list所有子列集合
List<List<Position>> subList=allsub(list);
//对该集合按size大小从大到小排列
Collections.sort(subList, new Comparator<List<Position>>() {
@Override
public int compare(List<Position> o1, List<Position> o2) {
// TODO Auto-generated method stub
if(o1.size()>o2.size())return -1;
else if(o1.size()==o2.size())return 0;
else return 1;
}
});
//第一个符合条件的就是最大值。
for(List<Position> l:subList) {
if(check(l)) {
System.out.println(l.size());
break;
}
}
}
static boolean check(List<Position> list) {
for(int i=0;i<list.size();i++) {
for(int j=i+1;j<list.size();j++) {
if(list.get(j).side(list.get(i))) {
return false;
}
}
}
return true;
}
static List<List<Position>> allsub(List<Position> list){
List<List<Position>> subList=new ArrayList<>();
for(int i=1;i<Math.pow(2,list.size());i++) {
int temp=i;
List<Position> sub=new ArrayList<>();
for(int j=0;j<list.size();j++) {
if((temp&1)==1) {
sub.add(list.get(j));
}
temp>>=1;
}
subList.add(sub);
}
return subList;
}
}
public class Demo {
public static void main(String[] args) throws Exception {
char[][] ok = new char[3][3];
ok[0] = new char[] { '*', '.', '*', '*', '.' };
ok[1] = new char[] { '*', '.', '*', '*', '*' };
ok[2] = new char[] { '*', '.', '*', '*', '.' };
System.out.println(search(ok));
}
public static int search(char[][] arr) {
// maxSize:从上下左右最大可用位置数,从最大数4开始依次去掉相邻位置有可用位置的位置
for (int maxSize = 4; maxSize > 0; maxSize--) {
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (arr[i][j] == '.') {// 判断该位置是否可用
int size = 0;// 定义上下左右相邻可用位置数
if (j > 0 && arr[i][j - 1] == '.') {
size++;// 判断左邻位置是否可用
}
if (j < arr[i].length - 1 && arr[i][j + 1] == '.') {
size++;// 右邻
}
if (i > 0 && arr[i - 1][j] == '.') {
size++;// 上邻
}
if (i < arr.length - 1 && arr[i + 1][j] == '.') {
size++;// 下邻
}
if (size == maxSize) {// 判断相邻可用位置数是否为最maxSize值
arr[i][j] = '*';// 将该位置设置为不可用
}
}
}
}
}
// 统计可用位置数
int size = 0;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (arr[i][j] == '.') {
size++;
}
}
}
return size;
}
}
public class Position {
private int x;
private int y;
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Position(int x, int y) {
super();
this.x = x;
this.y = y;
}
//判断相邻与否
boolean side(Position p) {
if(x==p.getX()&&(Math.abs(y-p.getY())==1))return true;
if(y==p.getY()&&(Math.abs(x-p.getX())==1))return true;
return false;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return getX()+":"+getY();
}
}
public class Test8 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int max=0;
char[][] c= {{'*','.','*','*','.'},{'*','.','*','*','*'},{'*','.','*','*','.'} } ;
//将所有可以做人的位子放入list中
List<Position> list=new ArrayList<Position>();
for (int i=0;i<c.length;i++) {
for(int j=0;j<c[0].length;j++) {
if(c[i][j]=='.') {
list.add(new Position(i, j));
}
}
}
//取该list所有子列集合
List<List<Position>> subList=allsub(list);
//取符合条件的子集的最大值
for(List<Position> l:subList) {
if(check(l)) {
if(l.size()>max)max=l.size();
}
}
System.out.println(max);
}
static boolean check(List<Position> list) {
for(int i=0;i<list.size();i++) {
for(int j=i+1;j<list.size();j++) {
if(list.get(j).side(list.get(i))) {
return false;
}
}
}
return true;
}
static List<List<Position>> allsub(List<Position> list){
List<List<Position>> subList=new ArrayList<>();
for(int i=0;i<Math.pow(2,list.size());i++) {
int temp=i;
List<Position> sub=new ArrayList<>();
for(int j=0;j<list.size();j++) {
if((temp&1)==1) {
sub.add(list.get(j));
}
temp>>=1;
}
subList.add(sub);
}
return subList;
}
}
package test;
public class StudentDamo{
public static void main(String[] args) throws Exception{
char [][]ok=new char[3][3];
ok[0]=new char[]{'*','.','*','*','.'};
ok[1]=new char[]{'*','.','*','*','*'};
ok[2]=new char[]{'*','.','*','*','.'};
int sum=0;
for (int i = 0; i < ok.length; i++) {
for (int j = 0; j < ok[0].length; j++) {
if(ok[i][j]=='.') {
search(ok, i, j);
sum++;
}
}
}
System.out.println(sum);
}
public static void search(char[][]arr,int emrow,int emclo) {
//只用判断下和右 我是一边过的 没有考虑最优解
if(emrow==arr.length-1&&emclo==arr[0].length-1) //右下角 不用管
return;
if(emrow==arr.length-1) {//是最后一行把 右面的 人 kill 了
arr[emrow][emclo+1]='*';
} else if(emclo==arr[0].length-1) {//同理 最后一列 把下面的kill
arr[emrow+1][emclo]='*';
} else {
arr[emrow][emclo+1]='*';//同上
arr[emrow+1][emclo]='*';
}
}
}
char [][]ok=new char[3][3];
ok[0]=new char[]{'*','*','*','.','.'};
ok[1]=new char[]{'*','*','*','.','*'};
ok[2]=new char[]{'*','*','*','*','*'};
这种是要输出1还是2?