- Bloxorz I
- 游戏外挂+部分游戏样例
- @ 2025-3-5 13:24:51
这是外挂
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int n,m,ex,ey;
char g[505][505];
bool vis[505][505][4];
int xl[4]={-1,1,0,0};
int yl[4]={0,0,-1,1};
//上下左右 
struct block
{
	int x,y;
	int a,b;
	int getf()
	{
		if(x==a && y==b)return 0;//立着 
		if(x==a && y!=b)return 1;//横着 
		if(x!=a && y==b)return 2;//竖着 
		return 0;
	}
	void vis_add()
	{
		vis[x][y][getf()]=1;
	}
	int check()
	{
		if(x<1 || x>n || y<1 || y>m || a<1 || a>n || b<1 || b>m)return -1;//超界了 
		if(vis[x][y][getf()])return -2;//标记了 
		if(g[x][y]=='#' || g[a][b]=='#')return -3;//跳空了 
		if(g[x][y]=='E' && x==a && y==b)return -4;//易碎单元格
		if(x==ex && y==ey && a==ex && b==ey)return 1;//答案 
		return 0;//正常状态 
	}
	void jump(int f)
	{
		int u=getf();
		if(u==0)//立着 
		{
				 if(f==0)x-=2,a--;
			else if(f==1)x++,a+=2;
			else if(f==2)y-=2,b--;
			else if(f==3)y++,b+=2;
		}
		else if(u==1)//横着 
		{
				 if(f==0)x--,a--;
			else if(f==1)x++,a++;
			else if(f==2)y--,b-=2;
			else if(f==3)y+=2,b++;
		}
		else if(u==2)//竖着 
		{
				 if(f==0)x--,a-=2;
			else if(f==1)x+=2,a++;
			else if(f==2)y--,b--;
			else if(f==3)y++,b++;
		}
	}
};
queue<pair<block,int> >q;
queue<vector<int> >v;//
void bfs(block s)
{
	memset(vis,0,sizeof vis);
	while(!q.empty())q.pop();
	
	while(!v.empty())v.pop();v.push({});//
	
	q.push({s,0});
	while(!q.empty())
	{
		block p=q.front().first;
		int c=q.front().second;
		q.pop();
		
		vector<int>r=v.front();v.pop();//
		
		int F=p.check();
		if(F<0)continue;
		//cout<<"xy:"<<p.x<<","<<p.y<<" ab:"<<p.a<<","<<p.b<<" F:"<<F<<" C:"<<c<<"\n";
		p.vis_add();
		 
		if(F==1)
		{
			
			for(int i=0;i<c;i++)//
			{
				if(r[i]==0)cout<<"上";
				if(r[i]==1)cout<<"下";
				if(r[i]==2)cout<<"左";
				if(r[i]==3)cout<<"右";
			}cout<<"\n";
			
			cout<<c<<"\n";
			return;
		}
		for(int i=0;i<4;i++)
		{
			block np=p;
			np.jump(i);
			if(np.check()<0)continue;
			
			vector<int>nr=r;//
			nr.push_back(i);
			v.push(nr);
			
			q.push({np,c+1});
		}
	}
	cout<<"Impossible\n";
}
int main()
{
	while(cin>>n>>m && n && m)
	{
		block s;
		s.x=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				cin>>g[i][j];
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				if(g[i][j]=='X' && !s.x)
				{
					s.x=i,s.y=j,s.a=i,s.b=j;
					for(int k=0;k<4;k++)
						if(g[i+xl[k]][j+yl[k]]=='X')
							s.a=i+xl[k],s.b=j+yl[k];
				}
				else if(g[i][j]=='O')
					ex=i,ey=j;
		bfs(s);
	}
	return 0;
}
样例1
8 12
############
#...########
#.X....#####
#.........##
##.........#
######..O..#
#######...##
############
答案
7
样例2
7 17
#################
#######.......###
#....##...##..###
#.........##....#
#.X..#######..O.#
#....########...#
#################
答案
22
样例3
11 16
################
####EEEEEEE#####
####EEEEEEE#####
#....#####...###
#...#######..###
#...#######..###
#.X.##....EEEEE#
#...##....EEEEE#
######.O.##EE.E#
######...##EEEE#
################
答案
28
样例4
12 17
#################
######......#####
######.##...#####
######.##.....###
#X.....#####....#
#####...####..O.#
#####...#####...#
#######.##..#####
#######.....#####
#######.....#####
########...######
#################
答案
35
样例5
12 14
##############
##....########
##.O..########
##...#########
##.###......##
##.###..##..##
#X......##...#
######.#####.#
######..####.#
######.......#
#########...##
##############
答案
49
样例6
12 16
################
#...E....E....##
#..########...##
#..#########...#
#...###...##.X.#
#...EEE.O.##...#
#...##E...##.###
###.##EEEEE..###
###...EE#EEE####
####..EEEEEE####
####...##..#####
################
答案
50
1 comments
- 
   C24zhuchengyu LV 8 @ 2025-3-7 11:03:49 C24zhuchengyu LV 8 @ 2025-3-7 11:03:49终于正常了 
- 1
Information
- ID
- 352
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 9
- Tags
- # Submissions
- 81
- Accepted
- 9
- Uploaded By
 
      