2011年度最变态迷宫数学题-java

2 篇文章 0 订阅

import java.util.ArrayList;
/**
* 2011年度最变态迷宫数学题
* @author Justplay(HBJ)
*
*/
public class Arithmetic {

private int d;
public ArrayList<String> arithmeticArray = new ArrayList<String>();
private int count;

public Arithmetic (int deep){
this.d = deep;
}

public void add7(int value ,int deep,boolean left,String load){// +7
if(deep>d){
System.out.println("("+deep + ")("+count + ") N此路算法过长: "+load);
return;
}
int tem = value+7;
load += "+"+7;
String _load = load;
deep ++;
if(left){
this.ride3(tem, deep,true,_load);
this.dim5(tem, deep,true,_load);
if(tem%2==0){
this.divide2(tem, deep,false,_load);
}
}else{
if(tem%2==0){
if(value==2012){
count++;
System.out.println("-----------------------Y此路算法通行: "+load);
this.arithmeticArray.add(load);
return;
}
this.divide2(tem, deep,true,_load);
}
}
}

public void divide2(int value ,int deep,boolean left,String load){// /2
if(deep>d){
System.out.println("("+deep + ")("+count + ") N此路算法过长: "+load);
return;
}
int tem = value /2;
load += "/"+2;
String _load = load;
deep++;
if(left){
this.ride3(tem, deep,true,_load);
this.dim5(tem, deep,true,_load);
this.add7(tem, deep, false,_load);
}else{
if(value==2012){
count++;
System.out.println("-----------------------Y此路算法通行: "+load);
this.arithmeticArray.add(load);
return;
}
this.add7(tem, deep, true,_load);
}
}

public void ride3(int value ,int deep,boolean left,String load){//X3
if(deep>d){
System.out.println("("+deep + ")("+count + ") N此路算法过长: "+load);
return;
}
int tem = value * 3 ;
load += "X"+3;
String _load = load;
deep++;
if(left){
if(tem==2012){
count++;
System.out.println("-----------------------Y此路算法通行: "+load);
this.arithmeticArray.add(load+" $(deep:"+deep+")");
return;
}
this.dim5(tem, deep, false,_load);
}else{
this.add7(tem, deep, false,_load);
this.dim5(tem, deep, true,_load);
if(tem%2==0){
this.divide2(tem, deep, false,_load);
}
}
}

public void dim5(int value ,int deep,boolean left,String load){ //-5
if(deep>d){
System.out.println("("+deep + ")("+count + ") N此路算法过长: "+load);
return;
}
int tem = value - 5 ;
load += "-"+5;
String _load = load;
deep++;
if(left){
if(tem==2012){
count++;
System.out.println("-----------------------Y此路算法通行: "+load);
this.arithmeticArray.add(load+" $(深度:"+deep+")");
return;
}
this.ride3(tem, deep, false,_load);
}else{
this.add7(tem, deep, false,_load);
this.ride3(tem, deep, true,_load);
if(tem%2==0){
this.divide2(tem, deep, false,_load);
}
}
}

public static void main(String args[]){
Arithmetic a = new Arithmetic (28);
a.add7(2011, 0, true,"");
System.out.println("结果集合");
for(String s :a.arithmeticArray){
System.out.println(s);
}
// +7/2+7/2+7-5X3/2+7/2+7X3-5/2+7/2+7-5X3-5X3/2+7-5X3/2+7-5
// int i = (((((((((((((2011+7)/2+7)/2+7-5)*3)/2+7)/2+7)*3-5)/2+7)/2+7-5)*3-5)*3)/2+7-5)*3)/2+7-5;
// System.out.println(i);
}
}

转载请注明:http://justplayoop1.iteye.com/admin/blogs/1292567
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值