62,614
社区成员
发帖
与我相关
我的任务
分享
TreeSet<Integer> set = new TreeSet<Integer>();
for (int i = 1; i < 100; i++) {
set.add(i);
}
for (int i = 1;; i++) {
int a = set.first();
int b = a + i;
System.out.println(i + ":" + a + "," + b);
set.remove(a);
if (!set.remove(b)) {
break;
}
}
int Result[aMax+1, bMax+1]={{0,...,0},{0,...,0}}; //0表示待求结果,1表示先拿者胜,-1表示先拿者负
for (int a=0; a<=aMax, a++) {
for (int b=0; b<=bMax; b++) {
if (a==0&&b==0) {
continue; //跳过没有石头的状态
}
int currentResult=Result[a,b];
if (currentResult!=0) {
continue;
}
if (a==b) {
currentResult = 1;
}
if (a==0) || (b==0) {
currentResult = 1;
}
if (currentResult==0) {
currentResult=-1;
}
if (currentResult==-1) {
//将可以一步走到当前状态的所有状态都设置为true
for (int t=1; a+t<=aMax&&b+t<=bMax; t++){
Result[a+t,b+t]=1;
Result[b+t,a+t]=1;
}
for (int t=1; a+t<=aMax; t++){
Result[a+t,b]=1;
Result[b,a+t]=1;
}
for (int t=1; b+t<=bMax; t++){
Result[a,b+t]=1;
Result[b+t,a]=1;
}
}
//设置当前状态变量
Result[a,b]=currentResult;
Result[b,a]=currentResult;
}
}
没有调试过,不过大致的思路应该没错