System.out.println("输入有误");
return;
}
intxuan=0;//过河决策方案标记
intxuan2=0;//返回决策方案标记
booleanff=false;//是否是选择返回方案标记
intinf=0;//选择过河方案成功与否标记
while(!
(x==0&&y==0)){//循环至全部都过河为止
if(ff==true){
xuan=0;//初始化返回决策方案
if(inf==0){//无适合的过河决策时,回溯返回方案
try{
V.remove(x*10+y);//弹出记录向量
}
catch(java.lang.ArrayIndexOutOfBoundsExceptione){//不能再弹出了,说明所有的方法都试过了,说明无解
System.out.println("无解");
return;
}
y=y+2;
yy=yy-2;//恢复
xuan2=s.pop().xuann;//弹出决策方案
//按照弹出的不同的返回决策方案来重新选择,避免了重复的选择
if(xuan2==-1){
xx=xx+1;
x=x-1;
yy=yy-1;
y=y+1;//恢复
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){//满足不被仆人杀掉,满足没有重复的安排
V.add(x*10+y);
s.push(newdk(0,1,-2));
}
else{
yy=yy+1;
y=y-1;
xx=xx-2;
x=x+2;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(2,0,-3));
}
else{
xx=xx+2;
x=x-2;
yy=yy-2;
y=y+2;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(0,2,-4));
}
else{
yy=yy+2;
y=y-2;
yy=yy-1;
xx=xx-1;
y=y+1;
x=x+1;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(1,1,-5));
}
else{//没有合适的返回方案,回溯过河方案
try{
V.remove(x*10+y);
}
catch(java.lang.ArrayIndexOutOfBoundsExceptione){
System.out.println("无解");
return;
}
yy=yy+1;
xx=xx+1;
y=y-1;
x=x-1;
xuan=s.pop().xuann;//过河方案的回溯
if(xuan==1){
x=x+1;
y=y+1;
xx=xx-1;
yy=yy-1;
}
elseif(xuan==2){
x=x+2;
xx=xx-2;
}
else{
y=y+2;
yy=yy-2;
}
ff=false;
continue;
}
}
}
}
}
elseif(xuan2==-2){
yy=yy+1;
y=y-1;
xx=xx-2;
x=x+2;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(2,0,-3));
}
else{
xx=xx+2;
x=x-2;
yy=yy-2;
y=y+2;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(0,2,-4));
}
else{
yy=yy+2;
y=y-2;
yy=yy-1;
xx=xx-1;
y=y+1;
x=x+1;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(1,1,-5));
}
else{
try{
V.remove(x*10+y);
}
catch(java.lang.ArrayIndexOutOfBoundsExceptione){
System.out.println("无解");
return;
}
yy=yy+1;
xx=xx+1;
y=y-1;
x=x-1;
xuan=s.pop().xuann;
if(xuan==1){
x=x+1;
y=y+1;
xx=xx-1;
yy=yy-1;
}
elseif(xuan==2){
x=x+2;
xx=xx-2;
}
else{
y=y+2;
yy=yy-2;
}
ff=false;
continue;
}
}
}
}
elseif(xuan2==-3){
xx=xx+2;
x=x-2;
yy=yy-2;
y=y+2;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(0,2,-4));
}
else{
yy=yy+2;
y=y-2;
yy=yy-1;
xx=xx-1;
y=y+1;
x=x+1;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(1,1,-5));
}
else{
try{
V.remove(x*10+y);
}
catch(java.lang.ArrayIndexOutOfBoundsExceptione){
System.out.println("无解");
return;
}
yy=yy+1;
xx=xx+1;
y=y-1;
x=x-1;
xuan=s.pop().xuann;
if(xuan==1){
x=x+1;
y=y+1;
xx=xx-1;
yy=yy-1;
}
elseif(xuan==2){
x=x+2;
xx=xx-2;
}
else{
y=y+2;
yy=yy-2;
}
ff=false;
continue;
}
}
}
elseif(xuan2==-4){
yy=yy+2;
y=y-2;
yy=yy-1;
xx=xx-1;
y=y+1;
x=x+1;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(1,1,-5));
}
else{
try{
V.remove(x*10+y);
}
catch(java.lang.ArrayIndexOutOfBoundsExceptione){
System.out.println("无解");
return;
}
yy=yy+1;
xx=xx+1;
y=y-1;
x=x-1;
xuan=s.pop().xuann;
if(xuan==1){
x=x+1;
y=y+1;
xx=xx-1;
yy=yy-1;
}
elseif(xuan==2){
x=x+2;
xx=xx-2;
}
else{
y=y+2;
yy=yy-2;
}
ff=false;
continue;
}
}
else{//一定没有合适的返回方案,回溯过河方案
try{
V.remove(x*10+y);
}
catch(java.lang.ArrayIndexOutOfBoundsExceptione){
System.out.println("无解");
return;
}
yy=yy+1;
xx=xx+1;
y=y-1;
x=x-1;
xuan=s.pop().xuann;
if(xuan==1){
x=x+1;
y=y+1;
xx=xx-1;
yy=yy-1;
}
elseif(xuan==2){
x=x+2;
xx=xx-2;
}
else{
y=y+2;
yy=yy-2;
}
ff=false;
continue;
}
}
else{//过河成功,返回方案的设定
xx=xx-1;
x=x+1;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(1,0,-1));
}
else{
xx=xx+1;
x=x-1;
yy=yy-1;
y=y+1;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(0,1,-2));
}
else{
yy=yy+1;
y=y-1;
xx=xx-2;
x=x+2;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(2,0,-3));
}
else{
xx=xx+2;
x=x-2;
yy=yy-2;
y=y+2;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(0,2,-4));
}
else{
yy=yy+2;
y=y-2;
yy=yy-1;
xx=xx-1;
y=y+1;
x=x+1;
if((x>=y&&xx>=yy)||(x==0)||(xx==0)&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(1,1,-5));
}
else{
try{
V.remove(x*10+y);
}
catch(java.lang.ArrayIndexOutOfBoundsExceptione){
System.out.println("无解");
return;
}
yy=yy+1;
xx=xx+1;
y=y-1;
x=x-1;
xuan=s.pop().xuann;
if(xuan==1){
x=x+1;
y=y+1;
xx=xx-1;
yy=yy-1;
}
elseif(xuan==2){
x=x+2;
xx=xx-2;
}
else{
y=y+2;
yy=yy-2;
}
ff=false;
continue;
}
}
}
}
}
}
}
ff=true;
inf=0;//此次轮渡成功的标志
//过河方案的设定
x=x-1;
y=y-1;
xx=xx+1;
yy=yy+1;
if(((x>=y&&xx>=yy)||(x==0)||(xx==0))&&xuan<1&&x>=0&&y>=0&&xx>=0&&yy>=0&&(V.indexOf(x*10+y)==-1||(V.size()-V.indexOf(x*10+y))%2!
=0)){
V.add(x*10+y);
s.push(newdk(1,1,1));
inf=1;
}
else{
x=x+