poj1753 Flip Game(beta 2)

 经过优化之后的第二个版本:任然是BFS,相比较第一个程序而言,删去了繁琐的二进制和十进制的转换,取而代之的是位运算。因此效率得到了很大的提高,但是相比较与POJ上的其他AC版本还不够。

Run ID User Problem Result Memory Time Language Code Length Submit Time
4844178 zen_chou 1753 Accepted 512K 157MS C 1976B 2009-03-24 19:08:10

#include #include #include #define MAXSTATE 65536 #define MAXSIZE 16 #define ALL_BLACK 65535 #define ALL_WHITE 0 //定义队列结构体 typedef struct node{ int data; struct node *next; }NODE; typedef struct{ NODE *front; NODE *rear; }QUEUE; //定义全局变量 int state[MAXSTATE]; QUEUE queue; void EnQueue(QUEUE *q, int d) { NODE *newNode; newNode=(NODE *)malloc(sizeof(NODE)); newNode->data=d; newNode->next=NULL; if(q->front!=NULL){ q->rear->next=newNode; q->rear=newNode; } else q->front=q->rear=newNode; } int DeQueue(QUEUE *q) { int temp; NODE *oldNode; if(q->front==NULL){ printf("List empty!/n"); return -1; } oldNode=q->front; temp=q->front->data; q->front=q->front->next; free(oldNode); return temp; } int Empty(QUEUE *q){ if(q->front==NULL) return 1; return 0; } int Flip(int id, int pos) { int state; state=id^1<=4) state ^= (1<<(pos-4));//正上方位置翻转 if (pos%4!=0) state ^= (1<<(pos-1)); if (pos<=11) state ^= (1<<(pos+4)); if ((pos+1)%4!=0) state ^= (1<<(pos+1)); return state; } void main(int argc, char*argv[]) { int i=0, cur_state_id=0, new_state_id; char c; QUEUE *q; q=&queue; memset(state,-1, 65536*sizeof(int)); //freopen("input.txt", "r", stdin); while(scanf("%c", &c)!=EOF){ if(c!='/n'){ if (c=='b') cur_state_id += 1<

你可能感兴趣的:(struct,null,优化,list,c,qq)