zoukankan      html  css  js  c++  java
  • A计划

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <cmath>
    using namespace std;
    
    struct node {
    	int x;
    	int y;
    	int z;
    	int step;
    };
    
    char Map[12][12][2];
    bool vis[12][12][2];
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    int n, m, t;
    int start[3];
    
    bool check(int x, int y, int z)
    {
    	if(x < 0 || y < 0 || x >= n || y >= m || Map[x][y][z] == '*')
    		return 1;
    	else 
    		return 0;
    }
    
    void bfs()
    {
    	memset(vis, false, sizeof(vis));
    	queue<node> q;
    	node a;
    	a.x = start[0];
    	a.y = start[1];
    	a.z = start[2];
    	a.step = 0;
    	vis[a.x][a.y][a.z] = true;
    	q.push(a);
    	while(!q.empty())
    	{
    		node b;
    		b = q.front();
    		q.pop();
    		
    		for(int i = 0; i < 4; ++ i)
    		{
    			node c = b;
    			c.x += dx[i];
    			c.y += dy[i];
    			c.step ++;
    			if(c.step > t)	break;
    			if(check(c.x, c.y, c.z) || vis[c.x][c.y][c.z])	continue;
    			vis[c.x][c.y][c.z] = true;
    			if(Map[c.x][c.y][c.z] == '#')
    			{
    				c.z = !c.z;
    				if(check(c.x, c.y, c.z) || vis[c.x][c.y][c.z] || Map[c.x][c.y][c.z] == '#')
    					continue;
    				vis[c.x][c.y][c.z] = true;
    			}
    			if(Map[c.x][c.y][c.z] == 'P')
    			{
    				cout << "YES" << endl;
    				return ;
    			}
    			q.push(c);
    		}
    	}
    	cout << "NO" << endl;
    }
    
    int main()
    {
    	int T;
    	cin >> T;
    	while(T --)
    	{
    		cin >> n >> m >> t;
    		for(int k = 0; k < 2; ++ k)
    		{
    			for(int i = 0; i < n; ++ i)
    			{
    				for(int j = 0; j < m; ++ j)
    				{
    					cin >> Map[i][j][k];
    					if(Map[i][j][k] == 'S')
    					{
    						start[0] = i;
    						start[1] = j;
    						start[2] = k;
    					}
    				}
    			}
    		} 
    		bfs();
    	}
    	
    	return 0;
    } 
    

      

    参考博客:https://blog.csdn.net/flytowns/article/details/86552772

  • 相关阅读:
    模拟循环单击事件实现layout中间panel全屏
    easyui tree自定义属性用法
    jquery给动态添加的dom元素绑定事件
    基于easyui fom分组插件
    ubuntu adb 安装
    vim状态保存跟恢复
    ubuntu-删除内核
    u盘安装14.04ubuntu系统
    findFocus-获得拥有焦点的控件
    xml中控件调用构造方法
  • 原文地址:https://www.cnblogs.com/mjn1/p/11630986.html
Copyright © 2011-2022 走看看