예제 #1
0
int main(int argc, char *argv[])
{
  int i = 45;
  for (i = 45; i <= 140; i++) {
    checkList[0] = i;
    triangleUp = upper(triangle(i));
    search(lower(triangle(i)));

    if (found == 1) {
      /* 输出递归信息 */
      printf("(3): %d -> %d\n", triangle(i), lower(triangle(i)));
      break;
    }

    checkList[0] = 0;
  }
  if (found == 1)
    /* 输出结果 */
    printf("%d(%d)+%d(%d)+%d(%d)+%d(%d)+%d(%d)+%d(%d)=%d\n", 
	   triangle(checkList[0]),checkList[0], square(checkList[1]),checkList[1],
	   pentagonal(checkList[2]),checkList[2], hexagonal(checkList[3]),checkList[3], 
	   heptagonal(checkList[4]),checkList[4], octagonal(checkList[5]), checkList[5],
	   triangle(checkList[0])+square(checkList[1])
	   +pentagonal(checkList[2])+hexagonal(checkList[3])
	   +heptagonal(checkList[4])+octagonal(checkList[5])
	   );
  
  return 0;
}
예제 #2
0
bool cycfig(int stage, int minbound)
{
    int testnum,testnum1;
    int testcase;
    switch(stage){
        case 1:
            for(testnum=10;testnum<100;testnum++){
                for(testnum1=testnum;testnum1<100;testnum1++){
                    if(triangle(testnum*100+testnum1)){
                        anscase[0]=3;
                        casefound[3]=true;
                        ans[0]=testnum;
                        ans[1]=testnum1;
                        if(cycfig(2,testnum))
                            return true;
                        casefound[3]=false;
                    }
                    if(square(testnum*100+testnum1)){
                        anscase[0]=4;
                        casefound[4]=true;
                        ans[0]=testnum;
                        ans[1]=testnum1;
                        if(cycfig(2,testnum))
                            return true;
                        casefound[4]=false;
                    }
                    if(pentagonal(testnum*100+testnum1)){
                        anscase[0]=5;
                        casefound[5]=true;
                        ans[0]=testnum;
                        ans[1]=testnum1;
                        if(cycfig(2,testnum))
                            return true;
                        casefound[5]=false;
                    }
                    if(hexagonal(testnum*100+testnum1)){
                        anscase[0]=6;
                        casefound[6]=true;
                        ans[0]=testnum;
                        ans[1]=testnum1;
                        if(cycfig(2,testnum))
                            return true;
                        casefound[6]=false;
                    }
                    if(heptagonal(testnum*100+testnum1)){
                        anscase[0]=7;
                        casefound[7]=true;
                        ans[0]=testnum;
                        ans[1]=testnum1;
                        if(cycfig(2,testnum))
                            return true;
                        casefound[7]=false;
                    }
                    if(octagonal(testnum*100+testnum1)){
                        anscase[0]=8;
                        casefound[8]=true;
                        ans[0]=testnum;
                        ans[1]=testnum1;
                        if(cycfig(2,testnum))
                            return true;
                        casefound[8]=false;
                    }
                }
            }
            break;
        case 2:
        case 3:
        case 4:
        case 5:
            for(testnum=minbound;testnum<100;testnum++){
                ans[stage]=testnum;
                for(testcase=3;testcase<9;testcase++){
                    if(casefound[testcase]==false){
                        switch(testcase){
                            case 3:
                                if(triangle(ans[stage-1]*100+ans[stage])){
                                    anscase[stage-1]=3;
                                    casefound[3]=true;
                                    if(cycfig(stage+1,minbound))
                                        return true;
                                    casefound[3]=false;
                                }
                                break;
                            case 4:
                                if(square(ans[stage-1]*100+ans[stage])){
                                    anscase[stage-1]=4;
                                    casefound[4]=true;
                                    if(cycfig(stage+1,minbound))
                                        return true;
                                    casefound[4]=false;
                                }
                                break;
                            case 5:
                                if(pentagonal(ans[stage-1]*100+ans[stage])){
                                    anscase[stage-1]=5;
                                    casefound[5]=true;
                                    if(cycfig(stage+1,minbound))
                                        return true;
                                    casefound[5]=false;
                                }
                                break;
                            case 6:
                                if(hexagonal(ans[stage-1]*100+ans[stage])){
                                    anscase[stage-1]=6;
                                    casefound[6]=true;
                                    if(cycfig(stage+1,minbound))
                                        return true;
                                    casefound[6]=false;
                                }
                                break;
                            case 7:
                                if(heptagonal(ans[stage-1]*100+ans[stage])){
                                    anscase[stage-1]=7;
                                    casefound[7]=true;
                                    if(cycfig(stage+1,minbound))
                                        return true;
                                    casefound[7]=false;
                                }
                                break;
                            case 8:
                                if(octagonal(ans[stage-1]*100+ans[stage])){
                                    anscase[stage-1]=8;
                                    casefound[8]=true;
                                    if(cycfig(stage+1,minbound))
                                        return true;
                                    casefound[8]=false;
                                }
                                break;
                            default: break;
                        }
                    }
                }
            }
            break;
        case 6:
            for(testcase=3;testcase<9;testcase++){
                if(!casefound[testcase]){
                    anscase[5]=testcase;
                    break;
                }
            }
            switch(testcase){
                case 3:
                    if(triangle(ans[5]*100+ans[0]))
                        return true;
                    break;
                case 4:
                    if(square(ans[5]*100+ans[0]))
                        return true;
                    break;
                case 5:
                    if(pentagonal(ans[5]*100+ans[0]))
                        return true;
                    break;
                case 6:
                    if(hexagonal(ans[5]*100+ans[0]))
                        return true;
                    break;
                case 7:
                    if(heptagonal(ans[5]*100+ans[0]))
                        return true;
                    break;
                case 8:
                    if(octagonal(ans[5]*100+ans[0]))
                        return true;
                    break;
                default: break;
            }
            break;
        default: return false;
    }
    return false;
}