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 xiaoqiangwj at 2008-10-25 03:18:24 on Problem 2965
#include <iostream>
#include <queue>
#include <stack>
using namespace std;

typedef struct{
	int pre;
	int change;
}RECORD;

int ChangeSwitch(int s,int x){
	int col[]={4369,8738,17476,34952,4369,8738,17476,34952,4369,8738,17476,34952,4369,8738,17476,34952};
	int row[]={15,15,15,15,240,240,240,240,3840,3840,3840,3840,61440,61440,61440,61440};
	int t[]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
	s=s^row[x];
	s=s^col[x];
	s=s^t[x];
	return s;
}

void PrintResult(int s, RECORD record[]){
	stack<int> list;
	int i=0;
	int r[]={4,4,4,4,3,3,3,3,2,2,2,2,1,1,1,1};
	int c[]={4,3,2,1,4,3,2,1,4,3,2,1,4,3,2,1};
	int size;
	while(record[s].pre!=0){
		list.push(record[s].change);
		s=record[s].pre;
	}
	size=list.size();
	cout <<size<<endl;
	for (i=0;i<size;i++){
		//cout <<list.top()<<endl;
		cout <<r[list.top()]<<" "<<c[list.top()]<<endl;
		list.pop();
	}
	return;
}

void bfs(queue<int> &q, RECORD record[], bool checked[]){
	int i;
	int x;
	int s=0;
	while(q.size()!=0){
		//cout <<"size:"<<q.size()<<endl;
		x=q.front();
		q.pop();
		if (!checked[x]){
			for (i=0;i<16;i++){
				s=ChangeSwitch(x,i);
		//		cout <<"s="<<s<<endl;
				if(!checked[s]){
				  record[s].pre=x;
				  record[s].change=i;
				}
				if (s!=0){
				checked[x]=true;
				if(!checked[s]) q.push(s);
				}else{
			//		cout <<record[0].pre<<endl;
					PrintResult(0, record);
					return;
				}
			}
		}
	}
}

超时了..

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