博文

简单去冗余解的24点解法(2007-03-25 20:11:00)

摘要:本程序并不能去掉全部冗余解,只是去掉一部分,并且写的尽可能简单,仅供大家参考。(注意:直接复制本段代码是无法正常运行的,除非手动重写-,-嘿嘿)#include <stdio.h> #define forT        for(t2=t1;t2<3;t2++)t[t2]=t[t2+1];#define GetNum(n)    {if(t1>0 && t[t1-1]==t[t1])continue;n=t[t1];forT}#define isTrue        if(23.9999<total && total<24.0001)#define argment        n1,GetSym(sym1),n2,GetSym(sym2),n3,GetSym(sym3),n4#define pt(str)        printf(str,argment);SearchCount++;continue;#define fsym(s)        for(long s=0;s<4;s++)#define isSct(s1,s2)    if(!(s1==1 && s2<=1 || s1==3 && s2>=2))#define tct           &n......

阅读全文(4371) | 评论:6

递归法生成2D迷宫(2007-03-25 19:46:00)

摘要:感谢网友forjane#include <stdio.h>#include <stdlib.h>#include <time.h>#define MAZE_MAXWIDTH    80#define MAZE_MAXHIGHT    26char map[MAZE_MAXWIDTH+2][MAZE_MAXHIGHT+2];void search(int x,int y){    static int zadd[4][2]={0,1,1,0,0,-1,-1,0};    int zx=x*2,zy=y*2,next,turn,i;    map[zx][zy]=1;  //当前坐标置1    turn=rand()%2? 1:3; //turn=1为顺时针3为逆时针    for(i=0,next=rand()%4;i<4;i++,next=(next+turn)%4)    {        if(map[zx+2*zadd[next][0]][zy+2*zadd[next][1]]==0)        {            map[zx+zadd[next][0]][zy+zadd[next][1]]=1; //中间的路径置1           &nb......

阅读全文(4971) | 评论:10