package http://www.doczj.com/doc/496e0b24d4d8d15abf234e14.html;
import java.util.LinkedList;
public class FarmerCrossRiver {
int[] route=new int[16];
int farmer(int location)
{
if((location & 0x08)!=0)
return 1;
else return 0;
}
int wolf(int location)
{
if((location & 0x04)!=0)
return 1;
else return 0;
}
int sheep(int location)
{
if((location & 0x02)!=0)
return 1;
else return 0;
}
int cabbage(int location)
{
if((location & 0x01)!=0)
return 1;
else return 0;
}
boolean isSafe(int location)
{
if((farmer(location)!=sheep(location))&&(sheep(location)==cabbage(location)))//如果农夫不在场且羊和白菜在一起则不安全
return false;
if((farmer(location)!=wolf(location))&&(wolf(location)==sheep(location)))//如果农夫不在且狼和羊在一起则不安全
return false;
return true;//其余情况安全
}
public static void main(String[] args)
{