我试了下可能比较笨 觉得不可能啊 因为1-10的和是45 无法让长宽平分 怎么组成正方呢? public class test2 { public static ArrayList data = new ArrayList(10); public static ArrayList boxs = new ArrayList(5); public static ArrayList height = new ArrayList(5); public static ArrayList width = new ArrayList(5);
e.g.:
a+b=10
a+c+d=10
e+f+g=10
e+h=10
.
.
.
然后是他们是1。10的数字
因为1-10的和是45 无法让长宽平分 怎么组成正方呢?
public class test2 {
public static ArrayList data = new ArrayList(10);
public static ArrayList boxs = new ArrayList(5);
public static ArrayList height = new ArrayList(5);
public static ArrayList width = new ArrayList(5);
static {
for(int i=0;i<10;i++){
data.add(new DataElement(i,false));
}
for(int i=0;i<5;i++){
data.add(new box());
}
}
static class DataElement{
int data;
boolean flag=false;
DataElement(int data,boolean flag){
this.data =data;
this.flag = flag;
}
}
static class box{
int height;
int width;
boolean flag = false;
box(){}
box(int height,int width){
this.height =height;
this.width = width;
}
}
public static void main(String arg[]){
//求算法 让1-10中5个数相加等于另外5个
//然后分别放在ArrayList height ArrayList width 里面
//任意对height width ArrayList 里的数进行组合就可以得到BOX
//可以扩展BOX得到面积
}
}
呵呵,思路有了,四个矩形首尾相接围成一圈,中间是一个矩形,呵呵,算法明天在写.做个记号
这样的话能确保找到所有的可能吗?我觉得可能会丢失