- 浏览: 10511 次
- 性别:
- 来自: 武汉
最新评论
-
windshome:
项目中文件多,怎么就会乱呢?,怎么就不利用阅读和调试?脑子不清 ...
java语法上最期待的改进 -
linliangyi2007:
让人很无语的想法,太肤浅了,投你个隐藏
java语法上最期待的改进 -
aws:
给接口加默认实现,那还要抽象类干嘛?
java语法上最期待的改进 -
delphixp:
给接口加默认实现 ---- 画蛇添足。将 void 当作 th ...
java语法上最期待的改进 -
01404421:
icefire 写道kobevaliant 写道我想要:多继承 ...
java语法上最期待的改进
三只大老虎和三只小老虎过河
三只大老虎分别是A.B.C三只小老虎分别是1.2.3,只有一条船,一次只能坐两只,A和1是母子俩,B和2是母子俩,C和3母子俩,只要任何一个母亲离开小老虎,小老虎都会被吃掉.
问题补充:大老虎都会划船 三只小老虎中只有1会划船
设大老虎为ABC,相应的小老虎为abc,其中c会划船。
package test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TigerRiver {
public static int[]tigersteps=new int[27*27*3] ;
public static Map<Integer,Status> map = new HashMap<Integer,Status>();
int i=0;
public TigerRiver() {
Status status = new Status(2, 2, 2, 2, 2, 2,false);
for(int i=0;i<tigersteps.length;i++){
tigersteps[i]=-1;
}
map.put(status.hashCode(), status);
tigersteps[status.hashCode()]=0;
}
public int minStep(Status status) throws IllegalArgumentException, IllegalAccessException {
int hascode=status.hashCode();
int minstep = tigersteps[hascode];
if (minstep != -1)
return minstep;
minstep = Integer.MAX_VALUE;
map.put(hascode, status);
List<Status> steps = status.getAllStep();
for (Status status2 : steps) {
int temhascode=status2.hashCode();
if(tigersteps[temhascode]==-1 && map.get(temhascode)!=null)continue;
int temstep = minStep(status2);
if (temstep < minstep-1) {
minstep = temstep+1;
status.setNextStatus(map.get(temhascode));
}
}
tigersteps[hascode]=minstep;
return minstep;
}
public static void print(Status status){
System.out.println(status);
while (status.getNextStatus()!=null) {
status=status.getNextStatus();
System.out.println(status);
}
}
public static void main(String[] args) {
Status status = new Status(0, 0, 0, 0, 0, 0,true);
TigerRiver tigerRiver=new TigerRiver();
try {
System.out.println("steps:"+tigerRiver.minStep(status));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
print(status);
}
}
package test;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.record.ContinueRecord;
public class Status {
public int A;
public int a;
public int B;
public int b;
public int C;
public int c;
private boolean left;
private Status nextStatus;
public Status(int big1, int small1, int big2, int small2, int big3,
int small3, boolean left) {
super();
this.A = big1;
this.a = small1;
this.B = big2;
this.b = small2;
this.C = big3;
this.c = small3;
this.left = left;
}
public Status(Status status) {
super();
this.A = status.A;
this.a = status.a;
this.B = status.B;
this.b = status.b;
this.C = status.C;
this.c = status.c;
this.left = status.left;
}
public List<Status> getAllStep() throws IllegalArgumentException,
IllegalAccessException {
List<Status> steps = new ArrayList<Status>();
if (left) {
List<Status> atob = getOneStepTrigers(0, 1);
for (Status status : atob) {
if (status.check())
steps.add(status);
}
List<Status> btoa = getOneStepTrigers(1, 0);
for (Status status : btoa) {
if (status.check())
steps.add(status);
}
if(getCount(0)>=2){
List<Status> atwob = getTwoStepTrigers(0, 1);
for (Status status : atwob) {
if (status.check())
steps.add(status);
}
}
if(getCount(1)>=2){
List<Status> btwoa = getTwoStepTrigers(1, 0);
for (Status status : btwoa) {
if (status.check())
steps.add(status);
}
}
} else {
List<Status> ctob = getOneStepTrigers(2, 1);
for (Status status : ctob) {
if (status.check())
steps.add(status);
}
List<Status> btoc = getOneStepTrigers(1, 2);
for (Status status : btoc) {
if (status.check())
steps.add(status);
}
if(getCount(2)>=2){
List<Status> ctwob = getTwoStepTrigers(2, 1);
for (Status status : ctwob) {
if (status.check())
steps.add(status);
}
}
if(getCount(1)>=2){
List<Status> btwoc = getTwoStepTrigers(1, 2);
for (Status status : btwoc) {
if (status.check())
steps.add(status);
}
}
}
if (A == 1 || B == 1 || C == 1 || c == 1) {
Status status = new Status(this);
status.left = !left;
steps.add(status);
}
return steps;
}
public boolean check() {
if (A < 0 || B < 0 || C < 0 || a < 0 || b < 0 || c < 0)
return false;
if (a == 0 && A != 0 || b == 0 && B != 0 || c == 0 && C != 0) {
if (A == 0 || B == 0 || C == 0) {
return false;
}
}
if (getCount(1) > 2)
return false;
if (a == 1 && A != 1 || b == 1 && B != 1 || c == 1 && C != 1) {
if (A == 1 || B == 1 || C == 1) {
return false;
}
}
if (a == 2 && A != 2 || b == 2 && B != 2 || c == 2 && C != 2) {
if (A == 2 || B == 2 || C == 2) {
return false;
}
}
return true;
}
private List<Field> getTrigers(int point) throws IllegalArgumentException,
IllegalAccessException {
List<Field> trigers = new ArrayList<Field>();
Field[] fields = this.getClass().getFields();
for (Field field : fields) {
if (((Integer) field.get(this)).intValue() == point) {
trigers.add(field);
}
}
return trigers;
}
private List<Status> getOneStepTrigers(int from, int to)
throws IllegalArgumentException, IllegalAccessException {
List<Status> trigers = new ArrayList<Status>();
List<Field> fList = getTrigers(from);
for (Field field : fList) {
Status status = new Status(this);
field.set(status, to);
trigers.add(status);
}
return trigers;
}
private List<Status> getTwoStepTrigers(int from, int to)
throws IllegalArgumentException, IllegalAccessException {
List<Status> trigers = new ArrayList<Status>();
List<Field> fList = getTrigers(from);
for (int i = 0; i < fList.size() - 1; i++) {
for (int j = i + 1; j < fList.size(); j++) {
Field fielda = fList.get(i);
Field fieldb = fList.get(j);
Status status = new Status(this);
fielda.set(status, to);
fieldb.set(status, to);
trigers.add(status);
}
}
return trigers;
}
private int getCount(int point) {
int count = 0;
if (A == point)
count++;
if (B == point)
count++;
if (C == point)
count++;
if (a == point)
count++;
if (b == point)
count++;
if (c == point)
count++;
return count;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
if (A == 0)
sb.append("A");
if (B == 0)
sb.append("B");
if (C == 0)
sb.append("C");
if (a == 0)
sb.append("a");
if (b == 0)
sb.append("b");
if (c == 0)
sb.append("c");
for (int i = getCount(0); i < 6; i++) {
sb.append(" ");
}
sb.append(" | ");
if (!left) {
sb.append(" ");
}
if (A == 1)
sb.append("A");
if (B == 1)
sb.append("B");
if (C == 1)
sb.append("C");
if (a == 1)
sb.append("a");
if (b == 1)
sb.append("b");
if (c == 1)
sb.append("c");
for (int i = getCount(1); i < 2; i++) {
sb.append(" ");
}
if (left) {
sb.append(" ");
}
sb.append(" | ");
if (A == 2)
sb.append("A");
if (B == 2)
sb.append("B");
if (C == 2)
sb.append("C");
if (a == 2)
sb.append("a");
if (b == 2)
sb.append("b");
if (c == 2)
sb.append("c");
for (int i = getCount(0); i < 6; i++) {
sb.append(" ");
}
return sb.toString();
}
public Status getNextStatus() {
return nextStatus;
}
public void setNextStatus(Status nextStatus) {
this.nextStatus = nextStatus;
}
@Override
public int hashCode() {
int prime = 1;
int result = 0;
result += prime * A;
prime *= 3;
result += prime * a;
prime *= 3;
result += prime * B;
prime *= 3;
result += prime * b;
prime *= 3;
if (left) {
result += prime * 1;
} else {
result += prime * 2;
}
prime *= 3;
result += prime * C;
prime *= 3;
result += prime * c;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Status other = (Status) obj;
if (A != other.A)
return false;
if (B != other.B)
return false;
if (C != other.C)
return false;
if (left != other.left)
return false;
if (nextStatus == null) {
if (other.nextStatus != null)
return false;
} else if (!nextStatus.equals(other.nextStatus))
return false;
if (a != other.a)
return false;
if (b != other.b)
return false;
if (c != other.c)
return false;
return true;
}
}
steps:27
ABCabc | |
ABab | Cc |
ABab | Cc |
ABab | C | c
ABab | C | c
ABCab | | c
ACa | Bb | c
ACa | Bb | c
ACa | B | bc
ACa | B | bc
Aa | BC | bc
Aa | BC | bc
Aa | | BCbc
Aa | Bb | Cc
Aa | Bb | Cc
ABab | | Cc
ab | AB | Cc
ab | AB | Cc
ab | A | BCc
ab | A | BCc
b | Aa | BCc
b | Aa | BCc
b | | ABCac
b | B | ACac
b | B | ACac
| Bb | ACac
| Bb | ACac
| | ABCabc
三只大老虎分别是A.B.C三只小老虎分别是1.2.3,只有一条船,一次只能坐两只,A和1是母子俩,B和2是母子俩,C和3母子俩,只要任何一个母亲离开小老虎,小老虎都会被吃掉.
问题补充:大老虎都会划船 三只小老虎中只有1会划船
设大老虎为ABC,相应的小老虎为abc,其中c会划船。
package test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TigerRiver {
public static int[]tigersteps=new int[27*27*3] ;
public static Map<Integer,Status> map = new HashMap<Integer,Status>();
int i=0;
public TigerRiver() {
Status status = new Status(2, 2, 2, 2, 2, 2,false);
for(int i=0;i<tigersteps.length;i++){
tigersteps[i]=-1;
}
map.put(status.hashCode(), status);
tigersteps[status.hashCode()]=0;
}
public int minStep(Status status) throws IllegalArgumentException, IllegalAccessException {
int hascode=status.hashCode();
int minstep = tigersteps[hascode];
if (minstep != -1)
return minstep;
minstep = Integer.MAX_VALUE;
map.put(hascode, status);
List<Status> steps = status.getAllStep();
for (Status status2 : steps) {
int temhascode=status2.hashCode();
if(tigersteps[temhascode]==-1 && map.get(temhascode)!=null)continue;
int temstep = minStep(status2);
if (temstep < minstep-1) {
minstep = temstep+1;
status.setNextStatus(map.get(temhascode));
}
}
tigersteps[hascode]=minstep;
return minstep;
}
public static void print(Status status){
System.out.println(status);
while (status.getNextStatus()!=null) {
status=status.getNextStatus();
System.out.println(status);
}
}
public static void main(String[] args) {
Status status = new Status(0, 0, 0, 0, 0, 0,true);
TigerRiver tigerRiver=new TigerRiver();
try {
System.out.println("steps:"+tigerRiver.minStep(status));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
print(status);
}
}
package test;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.record.ContinueRecord;
public class Status {
public int A;
public int a;
public int B;
public int b;
public int C;
public int c;
private boolean left;
private Status nextStatus;
public Status(int big1, int small1, int big2, int small2, int big3,
int small3, boolean left) {
super();
this.A = big1;
this.a = small1;
this.B = big2;
this.b = small2;
this.C = big3;
this.c = small3;
this.left = left;
}
public Status(Status status) {
super();
this.A = status.A;
this.a = status.a;
this.B = status.B;
this.b = status.b;
this.C = status.C;
this.c = status.c;
this.left = status.left;
}
public List<Status> getAllStep() throws IllegalArgumentException,
IllegalAccessException {
List<Status> steps = new ArrayList<Status>();
if (left) {
List<Status> atob = getOneStepTrigers(0, 1);
for (Status status : atob) {
if (status.check())
steps.add(status);
}
List<Status> btoa = getOneStepTrigers(1, 0);
for (Status status : btoa) {
if (status.check())
steps.add(status);
}
if(getCount(0)>=2){
List<Status> atwob = getTwoStepTrigers(0, 1);
for (Status status : atwob) {
if (status.check())
steps.add(status);
}
}
if(getCount(1)>=2){
List<Status> btwoa = getTwoStepTrigers(1, 0);
for (Status status : btwoa) {
if (status.check())
steps.add(status);
}
}
} else {
List<Status> ctob = getOneStepTrigers(2, 1);
for (Status status : ctob) {
if (status.check())
steps.add(status);
}
List<Status> btoc = getOneStepTrigers(1, 2);
for (Status status : btoc) {
if (status.check())
steps.add(status);
}
if(getCount(2)>=2){
List<Status> ctwob = getTwoStepTrigers(2, 1);
for (Status status : ctwob) {
if (status.check())
steps.add(status);
}
}
if(getCount(1)>=2){
List<Status> btwoc = getTwoStepTrigers(1, 2);
for (Status status : btwoc) {
if (status.check())
steps.add(status);
}
}
}
if (A == 1 || B == 1 || C == 1 || c == 1) {
Status status = new Status(this);
status.left = !left;
steps.add(status);
}
return steps;
}
public boolean check() {
if (A < 0 || B < 0 || C < 0 || a < 0 || b < 0 || c < 0)
return false;
if (a == 0 && A != 0 || b == 0 && B != 0 || c == 0 && C != 0) {
if (A == 0 || B == 0 || C == 0) {
return false;
}
}
if (getCount(1) > 2)
return false;
if (a == 1 && A != 1 || b == 1 && B != 1 || c == 1 && C != 1) {
if (A == 1 || B == 1 || C == 1) {
return false;
}
}
if (a == 2 && A != 2 || b == 2 && B != 2 || c == 2 && C != 2) {
if (A == 2 || B == 2 || C == 2) {
return false;
}
}
return true;
}
private List<Field> getTrigers(int point) throws IllegalArgumentException,
IllegalAccessException {
List<Field> trigers = new ArrayList<Field>();
Field[] fields = this.getClass().getFields();
for (Field field : fields) {
if (((Integer) field.get(this)).intValue() == point) {
trigers.add(field);
}
}
return trigers;
}
private List<Status> getOneStepTrigers(int from, int to)
throws IllegalArgumentException, IllegalAccessException {
List<Status> trigers = new ArrayList<Status>();
List<Field> fList = getTrigers(from);
for (Field field : fList) {
Status status = new Status(this);
field.set(status, to);
trigers.add(status);
}
return trigers;
}
private List<Status> getTwoStepTrigers(int from, int to)
throws IllegalArgumentException, IllegalAccessException {
List<Status> trigers = new ArrayList<Status>();
List<Field> fList = getTrigers(from);
for (int i = 0; i < fList.size() - 1; i++) {
for (int j = i + 1; j < fList.size(); j++) {
Field fielda = fList.get(i);
Field fieldb = fList.get(j);
Status status = new Status(this);
fielda.set(status, to);
fieldb.set(status, to);
trigers.add(status);
}
}
return trigers;
}
private int getCount(int point) {
int count = 0;
if (A == point)
count++;
if (B == point)
count++;
if (C == point)
count++;
if (a == point)
count++;
if (b == point)
count++;
if (c == point)
count++;
return count;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
if (A == 0)
sb.append("A");
if (B == 0)
sb.append("B");
if (C == 0)
sb.append("C");
if (a == 0)
sb.append("a");
if (b == 0)
sb.append("b");
if (c == 0)
sb.append("c");
for (int i = getCount(0); i < 6; i++) {
sb.append(" ");
}
sb.append(" | ");
if (!left) {
sb.append(" ");
}
if (A == 1)
sb.append("A");
if (B == 1)
sb.append("B");
if (C == 1)
sb.append("C");
if (a == 1)
sb.append("a");
if (b == 1)
sb.append("b");
if (c == 1)
sb.append("c");
for (int i = getCount(1); i < 2; i++) {
sb.append(" ");
}
if (left) {
sb.append(" ");
}
sb.append(" | ");
if (A == 2)
sb.append("A");
if (B == 2)
sb.append("B");
if (C == 2)
sb.append("C");
if (a == 2)
sb.append("a");
if (b == 2)
sb.append("b");
if (c == 2)
sb.append("c");
for (int i = getCount(0); i < 6; i++) {
sb.append(" ");
}
return sb.toString();
}
public Status getNextStatus() {
return nextStatus;
}
public void setNextStatus(Status nextStatus) {
this.nextStatus = nextStatus;
}
@Override
public int hashCode() {
int prime = 1;
int result = 0;
result += prime * A;
prime *= 3;
result += prime * a;
prime *= 3;
result += prime * B;
prime *= 3;
result += prime * b;
prime *= 3;
if (left) {
result += prime * 1;
} else {
result += prime * 2;
}
prime *= 3;
result += prime * C;
prime *= 3;
result += prime * c;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Status other = (Status) obj;
if (A != other.A)
return false;
if (B != other.B)
return false;
if (C != other.C)
return false;
if (left != other.left)
return false;
if (nextStatus == null) {
if (other.nextStatus != null)
return false;
} else if (!nextStatus.equals(other.nextStatus))
return false;
if (a != other.a)
return false;
if (b != other.b)
return false;
if (c != other.c)
return false;
return true;
}
}
steps:27
ABCabc | |
ABab | Cc |
ABab | Cc |
ABab | C | c
ABab | C | c
ABCab | | c
ACa | Bb | c
ACa | Bb | c
ACa | B | bc
ACa | B | bc
Aa | BC | bc
Aa | BC | bc
Aa | | BCbc
Aa | Bb | Cc
Aa | Bb | Cc
ABab | | Cc
ab | AB | Cc
ab | AB | Cc
ab | A | BCc
ab | A | BCc
b | Aa | BCc
b | Aa | BCc
b | | ABCac
b | B | ACac
b | B | ACac
| Bb | ACac
| Bb | ACac
| | ABCabc
评论
11 楼
DoubleEO
2009-01-14
我玩这个flash游戏,好像是僵尸和人的
10 楼
qianjigui
2009-01-13
感觉像操作系统的东西。
印象中可以使用图算法中的有向图、最小二分图覆盖等等。
印象中可以使用图算法中的有向图、最小二分图覆盖等等。
9 楼
regale
2009-01-13
三只大老虎和三只小老虎过河
三只大老虎分别是A.B.C三只小老虎分别是1.2.3,只有一条船,一次只能坐两只,A和1是母子俩,B和2是母子俩,C和3母子俩,只要任何一个母亲离开小老虎,小老虎都会被吃掉.
问题补充:大老虎都会划船 三只小老虎中只有1会划船
设大老虎为ABC,相应的小老虎为abc,其中c会划船。
再加一个条件,大老虎会主动上岸攻击小老虎
程序说明0表示老虎在左岸,1在船上,2在右岸
Status 表示某个时间点的快照
}
steps:38
ABCabc | |
ACac | Bb |
ACac | Bb |
ACac | B | b
ACac | B | b
ABCac | | b
ABC | ac | b
ABC | ac | b
ABC | c | ab
ABC | c | ab
ABCc | | ab
Cc | AB | ab
Cc | AB | ab
Cc | | ABab
Cc | Aa | Bb
Cc | Aa | Bb
ACc | a | Bb
AC | ac | Bb
ACa | c | Bb
Aa | Cc | Bb
Aa | Cc | Bb
Aa | c | BCb
Aa | bc | BC
Aa | b | BCc
Aa | Bb | Cc
Aa | Bb | Cc
ABab | | Cc
ab | AB | Cc
ab | AB | Cc
ab | | ABCc
ab | c | ABC
ab | c | ABC
b | ac | ABC
b | ac | ABC
b | c | ABCa
b | c | ABCa
| bc | ABCa
| bc | ABCa
| | ABCabc
三只大老虎分别是A.B.C三只小老虎分别是1.2.3,只有一条船,一次只能坐两只,A和1是母子俩,B和2是母子俩,C和3母子俩,只要任何一个母亲离开小老虎,小老虎都会被吃掉.
问题补充:大老虎都会划船 三只小老虎中只有1会划船
设大老虎为ABC,相应的小老虎为abc,其中c会划船。
再加一个条件,大老虎会主动上岸攻击小老虎
程序说明0表示老虎在左岸,1在船上,2在右岸
Status 表示某个时间点的快照
package test; import java.util.HashMap; import java.util.List; import java.util.Map; public class TigerRiver { public static int[]tigersteps=new int[27*27*3] ; public static Map<Integer,Status> map = new HashMap<Integer,Status>(); int i=0; public TigerRiver() { Status status = new Status(2, 2, 2, 2, 2, 2,false); for(int i=0;i<tigersteps.length;i++){ tigersteps[i]=-1; } map.put(status.hashCode(), status); tigersteps[status.hashCode()]=0; } public int minStep(Status status) throws IllegalArgumentException, IllegalAccessException { int hascode=status.hashCode(); int minstep = tigersteps[hascode]; if (minstep != -1) return minstep; minstep = Integer.MAX_VALUE; map.put(hascode, status); List<Status> steps = status.getAllStep(); for (Status status2 : steps) { int temhascode=status2.hashCode(); if(tigersteps[temhascode]==-1 && map.get(temhascode)!=null)continue; int temstep = minStep(status2); if (temstep < minstep-1) { minstep = temstep+1; status.setNextStatus(map.get(temhascode)); } } tigersteps[hascode]=minstep; return minstep; } public static void print(Status status){ System.out.println(status); while (status.getNextStatus()!=null) { status=status.getNextStatus(); System.out.println(status); } } public static void main(String[] args) { Status status = new Status(0, 0, 0, 0, 0, 0,true); TigerRiver tigerRiver=new TigerRiver(); try { System.out.println("steps:"+tigerRiver.minStep(status)); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } print(status); } } package test; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import org.apache.poi.hssf.record.ContinueRecord; public class Status { public int A; public int a; public int B; public int b; public int C; public int c; private boolean left; private Status nextStatus; public Status(int big1, int small1, int big2, int small2, int big3, int small3, boolean left) { super(); this.A = big1; this.a = small1; this.B = big2; this.b = small2; this.C = big3; this.c = small3; this.left = left; } public Status(Status status) { super(); this.A = status.A; this.a = status.a; this.B = status.B; this.b = status.b; this.C = status.C; this.c = status.c; this.left = status.left; } public List<Status> getAllStep() throws IllegalArgumentException, IllegalAccessException { List<Status> steps = new ArrayList<Status>(); if (left) { List<Status> atob = getOneStepTrigers(0, 1); for (Status status : atob) { if (status.check()) steps.add(status); } List<Status> btoa = getOneStepTrigers(1, 0); for (Status status : btoa) { if (status.check()) steps.add(status); } if(getCount(0)>=2){ List<Status> atwob = getTwoStepTrigers(0, 1); for (Status status : atwob) { if (status.check()) steps.add(status); } } if(getCount(1)>=2){ List<Status> btwoa = getTwoStepTrigers(1, 0); for (Status status : btwoa) { if (status.check()) steps.add(status); } } } else { List<Status> ctob = getOneStepTrigers(2, 1); for (Status status : ctob) { if (status.check()) steps.add(status); } List<Status> btoc = getOneStepTrigers(1, 2); for (Status status : btoc) { if (status.check()) steps.add(status); } if(getCount(2)>=2){ List<Status> ctwob = getTwoStepTrigers(2, 1); for (Status status : ctwob) { if (status.check()) steps.add(status); } } if(getCount(1)>=2){ List<Status> btwoc = getTwoStepTrigers(1, 2); for (Status status : btwoc) { if (status.check()) steps.add(status); } } } if (A == 1 || B == 1 || C == 1 || c == 1) { Status status = new Status(this); status.left = !left; steps.add(status); } return steps; } public boolean check() { if (A < 0 || B < 0 || C < 0 || a < 0 || b < 0 || c < 0) return false; if (a == 0 && A != 0 || b == 0 && B != 0 || c == 0 && C != 0) { if (A == 0 || B == 0 || C == 0) { return false; } } if (a == 0 && A ==2 || b == 0 && B ==2 || c == 0 && C == 2) { if (A == 1 || B == 1 || C == 1) { return false; } } if (getCount(1) > 2) return false; if (a == 1 && A != 1 || b == 1 && B != 1 || c == 1 && C != 1) { if (A == 1 || B == 1 || C == 1) { return false; } } if (a == 2 && A != 2 || b == 2 && B != 2 || c == 2 && C != 2) { if (A == 2 || B == 2 || C == 2) { return false; } } if (a == 2 && A == 0 || b == 2 && B == 0 || c == 2 && C == 0) { if (A == 1 || B == 1 || C == 1) { return false; } } return true; } private List<Field> getTrigers(int point) throws IllegalArgumentException, IllegalAccessException { List<Field> trigers = new ArrayList<Field>(); Field[] fields = this.getClass().getFields(); for (Field field : fields) { if (((Integer) field.get(this)).intValue() == point) { trigers.add(field); } } return trigers; } private List<Status> getOneStepTrigers(int from, int to) throws IllegalArgumentException, IllegalAccessException { List<Status> trigers = new ArrayList<Status>(); List<Field> fList = getTrigers(from); for (Field field : fList) { Status status = new Status(this); field.set(status, to); trigers.add(status); } return trigers; } private List<Status> getTwoStepTrigers(int from, int to) throws IllegalArgumentException, IllegalAccessException { List<Status> trigers = new ArrayList<Status>(); List<Field> fList = getTrigers(from); for (int i = 0; i < fList.size() - 1; i++) { for (int j = i + 1; j < fList.size(); j++) { Field fielda = fList.get(i); Field fieldb = fList.get(j); Status status = new Status(this); fielda.set(status, to); fieldb.set(status, to); trigers.add(status); } } return trigers; } private int getCount(int point) { int count = 0; if (A == point) count++; if (B == point) count++; if (C == point) count++; if (a == point) count++; if (b == point) count++; if (c == point) count++; return count; } @Override public String toString() { StringBuffer sb = new StringBuffer(); if (A == 0) sb.append("A"); if (B == 0) sb.append("B"); if (C == 0) sb.append("C"); if (a == 0) sb.append("a"); if (b == 0) sb.append("b"); if (c == 0) sb.append("c"); for (int i = getCount(0); i < 6; i++) { sb.append(" "); } sb.append(" | "); if (!left) { sb.append(" "); } if (A == 1) sb.append("A"); if (B == 1) sb.append("B"); if (C == 1) sb.append("C"); if (a == 1) sb.append("a"); if (b == 1) sb.append("b"); if (c == 1) sb.append("c"); for (int i = getCount(1); i < 2; i++) { sb.append(" "); } if (left) { sb.append(" "); } sb.append(" | "); if (A == 2) sb.append("A"); if (B == 2) sb.append("B"); if (C == 2) sb.append("C"); if (a == 2) sb.append("a"); if (b == 2) sb.append("b"); if (c == 2) sb.append("c"); for (int i = getCount(0); i < 6; i++) { sb.append(" "); } return sb.toString(); } public Status getNextStatus() { return nextStatus; } public void setNextStatus(Status nextStatus) { this.nextStatus = nextStatus; } @Override public int hashCode() { int prime = 1; int result = 0; result += prime * A; prime *= 3; result += prime * a; prime *= 3; result += prime * B; prime *= 3; result += prime * b; prime *= 3; if (left) { result += prime * 1; } else { result += prime * 2; } prime *= 3; result += prime * C; prime *= 3; result += prime * c; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Status other = (Status) obj; if (A != other.A) return false; if (B != other.B) return false; if (C != other.C) return false; if (left != other.left) return false; if (nextStatus == null) { if (other.nextStatus != null) return false; } else if (!nextStatus.equals(other.nextStatus)) return false; if (a != other.a) return false; if (b != other.b) return false; if (c != other.c) return false; return true; }
}
steps:38
ABCabc | |
ACac | Bb |
ACac | Bb |
ACac | B | b
ACac | B | b
ABCac | | b
ABC | ac | b
ABC | ac | b
ABC | c | ab
ABC | c | ab
ABCc | | ab
Cc | AB | ab
Cc | AB | ab
Cc | | ABab
Cc | Aa | Bb
Cc | Aa | Bb
ACc | a | Bb
AC | ac | Bb
ACa | c | Bb
Aa | Cc | Bb
Aa | Cc | Bb
Aa | c | BCb
Aa | bc | BC
Aa | b | BCc
Aa | Bb | Cc
Aa | Bb | Cc
ABab | | Cc
ab | AB | Cc
ab | AB | Cc
ab | | ABCc
ab | c | ABC
ab | c | ABC
b | ac | ABC
b | ac | ABC
b | c | ABCa
b | c | ABCa
| bc | ABCa
| bc | ABCa
| | ABCabc
8 楼
regale
2009-01-13
你的意思是B会主动上岸去吃c?如果这样,我把判断再改动一下
7 楼
amozon
2009-01-13
没看到你还有只有c会划船,那么只要开始的Cc改成Aa,或者Bb
6 楼
amozon
2009-01-13
ABCabc | |
ABab | Cc |
ABab | Cc |
ABab | C | c
ABab | C | c
ABCab | | c
ABC | ab | c
ABC | ab | c
ABC | a | bc
ABC | a | bc
Aa | BC | bc
Aa | BC | bc
Aa | | BCbc
Aa | Bb | Cc
Aa | Bb | Cc
ABab | | Cc
ab | AB | Cc
ab | AB | Cc
ab | c | ABC
ab | c | ABC
b | ac | ABC
b | c | ABCa
b | c | ABCa
ABab | Cc |
ABab | Cc |
ABab | C | c
ABab | C | c
ABCab | | c
ABC | ab | c
ABC | ab | c
ABC | a | bc
ABC | a | bc
Aa | BC | bc
Aa | BC | bc
Aa | | BCbc
Aa | Bb | Cc
Aa | Bb | Cc
ABab | | Cc
ab | AB | Cc
ab | AB | Cc
ab | c | ABC
ab | c | ABC
b | ac | ABC
b | c | ABCa
b | c | ABCa
5 楼
amozon
2009-01-13
ACa | Bb | c
ACa | Bb | c
ACa | B | bc
这样 B 会吃掉 c
ACa | Bb | c
ACa | B | bc
这样 B 会吃掉 c
4 楼
regale
2009-01-13
就大C,大老虎,不是小老虎
3 楼
amozon
2009-01-13
Step 8: B will eat c
那步应该是 ab过去,而不是Bb....
那步应该是 ab过去,而不是Bb....
2 楼
ahrhu
2009-01-13
不过我想应该是很有意思的吧
1 楼
ahrhu
2009-01-13
我看不明白
相关推荐
在本文中,我们将深入探讨如何使用STM32F103C8T6微控制器来实现无源蜂鸣器播放“两只老虎”这首经典儿歌。STM32是一款基于ARM Cortex-M3内核的高性能、低功耗的微控制器,广泛应用于嵌入式系统设计。无源蜂鸣器是一...
小老虎完美破解绝对真实可用,谢谢!
《一只窝囊的大老虎》说课稿.doc
在本文中,我们将深入探讨如何使用STM32微控制器来驱动蜂鸣器并播放音乐,以实现"两只老虎"这首儿歌。STM32是一款基于ARM Cortex-M内核的高性能微控制器,广泛应用于嵌入式系统设计。我们将从以下几个方面进行讲解:...
《小老鼠和大老虎》.ppt
"监控工具三只老虎眼网管工具"是一款专为网络管理员设计的强大监控软件,它集成了多种功能,帮助用户有效地管理和监控网络运行状态。作为网管的得力助手,这款工具能够提供实时、准确的数据反馈,确保网络稳定、高效...
C51蜂鸣器播放两只老虎和小星星代码,怎么根据谱子打表呢。。。自己摸索吧
这篇文档是关于小学四年级语文课程的一个教学设计,主要针对部编版教材第六单元的《一只窝囊的大老虎》这一课题。课程难点在于引导学生理解并分析主角在排练和演出过程中心情的变化及其原因,同时体验童年生活的丰富...
5. 在课文整体梳理中,明确文章分为期盼参加演出、饰老虎没成功、寻找失败根源三个部分,同时揭示了老师和演“哥哥”的小朋友在表演理念上的不同。 6. 重点段落品析环节,通过分析作者在舞台上表演时的心理状态和...
在活动中,教师首先通过展示图片引出故事,以一只流口水的大老虎和三只小猪为角色,引发幼儿的兴趣。大老虎是故事中的反派角色,但其形象设计有趣,增加了故事的幽默感。教师通过模仿大老虎的声音和动作,使幼儿更...
3. 因为这只窝囊的大老虎,动作虽然笨拙,但是却很可爱,很有趣。 - 七、略 以上内容详细阐述了文本中的关键知识点,包括词语学习、成语运用、文本结构分析、角色心理和情节理解,以及思维拓展训练。这些知识点对于...
这篇PPT教案主要围绕一个儿童故事展开,讲述的是北京动物园里的一只大老虎因为生病无法照顾自己的三只小老虎,于是饲养员找来了一只大花狗代替老虎妈妈的角色,来喂养和照顾小老虎。这个故事教育孩子们关于爱心、...
《汇编音乐程序--两只老虎》 在计算机科学领域,汇编语言是一种低级编程语言,它是计算机硬件能够直接理解的指令集的符号表示。汇编语言与机器语言紧密相关,但比机器语言更易读,因为它使用了助记符来代表机器指令...
【小老虎的名片(语言)】是一个以教育儿童理解名片功能为主题的学习活动,旨在通过一个生动的故事引导孩子们认识名片在日常生活中的重要性。这个活动主要包含三个部分:故事讲述、幼儿讨论和家庭作业。 首先,教师...
用Python画一只可爱的小老虎,祝你虎年大吉!
这篇PPT课件是关于语文课程的一份教学材料,标题为"一只窝囊的大老虎",适合四年级上册的学生学习。课件内容主要围绕一篇课文展开,课文出自叶至善的作品,他是著名作家叶圣陶的儿子。课文的主角是一只被描绘成不太...
这篇教学设计针对的是小学四年级语文课程,课文《一只窝囊的大老虎》,主要讲述了作者参与校园剧表演,扮演老虎却因未完成“豁虎跳”而感到窝囊的故事。教学设计围绕以下几个方面展开: 1. **教材内容分析**:课文...
这篇文档主要介绍了一篇以"一只窝囊的大老虎"为题的课文,它属于小学四年级上册的人教版语文教材。这篇课文的教学目标主要包括以下几个方面: 1. 学习汉字:学生需要学会识别和书写9个生字,如"囊、羡",并掌握12个...
第三段中,大老虎采取行动改正错误,尝试修复与小老鼠的友情,孩子们被问及小老鼠对此的反应,以此深化理解道歉和原谅的重要性。 在完整欣赏故事后,教师邀请孩子们分享自己与朋友之间的矛盾和解决方法,以此强化...
在这个看似简单的儿童故事《小老鼠和大老虎 (4).ppt》中,其实蕴含了一些重要的教育理念和生活哲理,同时也可引发对信息技术在儿童教育中应用的思考。 首先,故事中的"小老鼠"和"大老虎"是常见的动物角色,常常被...