一些存档。。。

<pre name="code" class="cpp">#include <iostream>  
#include <stdio.h>  
#include <string.h>  
#include <algorithm>  
#include <queue>  
#include <map>  
#include <vector>  
#include <stack>
#include <set>  
#include <string>  
#include <math.h>  
using namespace std;  


const int NUM=7;
//0~7的阶乘 
int factory[NUM]={0,1,2,6,24,120,720};

//康托展开 
int Cantor(int perm[]){
	int i,j,counted;
	int result=0;
	for(i=0;i<NUM;++i){
		counted=0;
		for(j=i+1;j<NUM;++j)
			if(perm[i]>perm[j])++counted;
		result=result+counted*factory[NUM-i-1];
	}
	return result;
}

//3进制转换为10进制 
int _32dec(int ori[]){
	int res=0;
	for(int i=0;i<NUM;i++){
		res*=3;
		res+=ori[i];
	}
	return res;
}

/*
 *存储除了DBL块以外的7个块的位置和方向信息 
 * 1:UBR 
 * 2:UFR
 * 3:UFL
 * 4:UBL
 * 5:DBR
 * 6:DFR
 * 7:DFL
 * 
 */
struct Node{
	int permutation[7];
	int orientation[7];
	
	void U(){
		int t=permutation[3];
		permutation[3]=permutation[2];
		permutation[2]=permutation[1];
		permutation[1]=permutation[0];
		permutation[0]=t;
		//
		t=orientation[3];
		orientation[3]=orientation[2];
		orientation[2]=orientation[1];
		orientation[1]=orientation[0];
		orientation[0]=t;
	}
	
	void R(){
		int t=permutation[0];
		permutation[0]=permutation[1];
		permutation[1]=permutation[5];
		permutation[5]=permutation[4];
		permutation[4]=t;
		//o
		t=orientation[0];
		orientation[0]=orientation[1];
		orientation[1]=orientation[5];
		orientation[5]=orientation[4];
		orientation[4]=t;
		orientation[0]+=1; orientation[0]%=3;
		orientation[1]+=2; orientation[1]%=3;
		orientation[5]+=1; orientation[5]%=3;
		orientation[4]+=2; orientation[4]%=3;
	}
	
	void F(){
		int t=permutation[1];
		permutation[1]=permutation[2];
		permutation[2]=permutation[6];
		permutation[6]=permutation[5];
		permutation[5]=t;
		//o
		t=orientation[1];
		orientation[1]=orientation[2];
		orientation[2]=orientation[6];
		orientation[6]=orientation[5];
		orientation[5]=t;
		orientation[1]+=1; orientation[1]%=3;
		orientation[2]+=2; orientation[2]%=3;
		orientation[6]+=1; orientation[6]%=3;
		orientation[5]+=2; orientation[5]%=3;
	}
	
	void D(){
		U(); U(); U();
	}
	
	void L(){
		R(); R(); R();
	}
	
	void B(){
		F(); F(); F();
	}
};

//哈希函数
//返回的最小值是0
//返回的最大值小于1.2e7
// 
int _hash(Node& nd){
	int hash_p=Cantor(nd.permutation);
	int hash_o=_32dec(nd.orientation);
	//2187是三进制2222222 
	return hash_p*2187+hash_o;
}

bool vis[12000000];
char premove[12000000];
int prestate[12000000];

queue<Node> que;
void BFS(Node s){
	while(!que.empty())que.pop();
	
	memset(vis,0,sizeof(vis));
	que.push(s);
	vis[_hash(s)]=1;
	while(!que.empty()){
		Node cur=que.front(); que.pop();
		int hashcur=_hash(cur);
		
		Node t;
		int h;
		//cout<<hashcur<<endl;
		for(int k=0;k<3;k++){
			t=cur;
			
			if(k==0)t.U();
			if(k==1)t.D();
			if(k==2)t.R();
			if(k==3)t.L();
			if(k==4)t.F();
			if(k==5)t.B();

			h=_hash(t);
			if(!vis[h]){
				que.push(t);
				vis[h]=1;
				if(k==0)premove[h]='U';
				if(k==1)premove[h]='D';
				if(k==2)premove[h]='R';
				if(k==3)premove[h]='L';
				if(k==4)premove[h]='F';
				if(k==5)premove[h]='B';
				prestate[h]=hashcur;
			}
			if(h==0)break;
			
		}
		if(h==0)break;
	}
}


int main(){
	int n;
	while(cin>>n){
		Node solved_state;
		for(int i=0;i<7;i++){
			solved_state.orientation[i]=0;
			solved_state.permutation[i]=i;
		}
	
		char str[20];
		scanf("%s",str);
		
		int sz=strlen(str);
		
		for(int i=0;i<sz;i++){
			if(str[i]=='U'){
				solved_state.U();
			}
			if(str[i]=='F'){
				solved_state.F();
			}
			if(str[i]=='R'){
				solved_state.R();
			}
		}
		
		
		BFS(solved_state);
		cout<<"finished"<<endl;
		stack<char> sta;
		int tmp=0;
		sta.push(premove[tmp]);
		tmp=prestate[tmp];
		while(tmp){
			sta.push(premove[tmp]);
			tmp=prestate[tmp];
		}
		while(!sta.empty()){
			cout<<sta.top()<<" ";
			sta.pop();
		}cout<<endl;
	}
	
	return 0;
} 




                
7-5 哲哲打游戏 分数 25 作者 DAI, Longao 单位 杭州百腾教育科技有限公司 哲哲是一位硬核游戏玩家。最近一款名叫《达诺达诺》的新游戏刚刚上市,哲哲自然要快速攻略游戏,守护硬核游戏玩家的一切! 为简化模型,我们不妨假设游戏有 N 个剧情点,通过游戏里不同的操作或选择可以从某个剧情点去往另外一个剧情点。此外,游戏还设置了一些存档,在某个剧情点可以将玩家的游戏进度保存在一个档位上,读取存档后可以回到剧情点,重新进行操作或者选择,到达不同的剧情点。 为了追踪硬核游戏玩家哲哲的攻略进度,你打算写一个程序来完成这个工作。假设你已经知道了游戏的全部剧情点和流程,以及哲哲的游戏操作,请你输出哲哲的游戏进度。 输入格式: 输入第一行是两个正整数 N 和 M (1≤N,M≤10 5 ),表示总共有 N 个剧情点,哲哲有 M 个游戏操作。 接下来的 N 行,每行对应一个剧情点的发展设定。第 i 行的第一个数字是 K i ​ ,表示剧情点 i 通过一些操作或选择能去往下面 K i ​ 个剧情点;接下来有 K i ​ 个数字,第 k 个数字表示做第 k 个操作或选择可以去往的剧情点编号。 最后有 M 行,每行第一个数字是 0、1 或 2,分别表示: 0 表示哲哲做出了某个操作或选择,后面紧接着一个数字 j,表示哲哲在当前剧情点做出了第 j 个选择。我们保证哲哲的选择永远是合法的。 1 表示哲哲进行了一次存档,后面紧接着是一个数字 j,表示存档放在了第 j 个档位上。 2 表示哲哲进行了一次读取存档的操作,后面紧接着是一个数字 j,表示读取了放在第 j 个位置存档。 约定:所有操作或选择以及剧情点编号都从 1 号开始。存档的档位不超过 100 个,编号也从 1 开始。游戏默认从 1 号剧情点开始。总的选项数(即 ∑K i ​ )不超过 10 6 。 输出格式: 对于每个 1(即存档)操作,在一行中输出存档的剧情点编号。 最后一行输出哲哲最后到达的剧情点编号。 输入样例: 10 11 3 2 3 4 1 6 3 4 7 5 1 3 1 9 2 3 5 3 1 8 5 1 9 2 8 10 0 1 1 0 3 0 1 1 2 0 2 0 2 2 2 0 3 0 1 1 1 0 2 输出样例: 1 3 9 10 样例解释: 简单给出样例中经过的剧情点顺序: 1 -> 4 -> 3 -> 7 -> 8 -> 3 -> 5 -> 9 -> 10。 档位 1 开始存的是 1 号剧情点;档位 2 存的是 3 号剧情点;档位 1 后来又存了 9 号剧情点。 代码长度限制 16 KB Java (javac) 时间限制 800 ms 内存限制 64 MB Python (python3) 时间限制 1000 ms 内存限制 64 MB 其他编译器 时间限制 400 ms 内存限制 64 MB 栈限制 8192 KB
最新发布
11-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值