Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为何不过呢?

Posted by flumer at 2009-07-26 02:34:39 on Problem 1753
c0n是改变颜色用的
几乎什么都加了,为何A不掉呢?

/*unsolved*/

#include<stdio.h>
#include<math.h>
#include<limits.h>
#include<stdbool.h>
#include<stdlib.h>
#include<string.h>
#define NDEBUG -1
#include<assert.h>
#define c0n(a,i) a=(a>>(i)&1==1)?(a&~(1<<(i))):(a|(1<<(i)))


char map[16];
bool b[65536];
long st;
long ed[2];
long q[65536];
long dep[65536];
long  h,t;
int bfs()
{
	int i,sta;
	h=0;t=1;
	q[0]=st;
	dep[0]=0;
	while(h<t){
		for(i=0;i<16;i++){
			sta=q[h];
			if(i%4==0)c0n(sta,i+1);
			else if(i%4==3)c0n(sta,i-1);
			else{
				c0n(sta,i+1);
				c0n(sta,i-1);
			}
			if(i>=0&&i<4)c0n(sta,i+4);
			else if(i>=12&&i<16)c0n(sta,i-4);
			else{
				c0n(sta,i+4);
				c0n(sta,i-4);
			}
			sta=c0n(sta,i);

			if(!b[sta]){
				b[sta]=true;
				q[t]=sta;
				dep[t]=dep[h]+1;
				if(sta==ed[0]||sta==ed[1]){printf("%ld\n",dep[t]);return 0;}
				t++;
			}
		}
		h++;
	}
	return 1;
}


int main(void)
{
	int i,j;
	//freopen("t2","r",stdin);
	//freopen("t2o","w",stdout);
	memset(q,0,sizeof(q));
	memset(dep,0,sizeof(dep));
	for(i=0;i<16;i++){
		scanf("%c",&map[i]);
		if(i%4==3)scanf("\n");
		if(map[i]=='b')st=st&~(1<<i);
		else st=st|(1<<i);
	}
	ed[0]=0;
	ed[1]=65535;
	b[st]=true;
	if(st==ed[0]||st==ed[1])printf("0\n");
	if(bfs())printf("Impossibe\n");
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator