Curling 2.0

Curling 2.0
Time Limit: 1000MS		Memory Limit: 65536K
Total Submissions: 22403		Accepted: 9089
Description

On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from ours. The game is played on an ice game board on which a square mesh is marked. They use only a single stone. The purpose of the game is to lead the stone from the start to the goal with the minimum number of moves.

Fig. 1 shows an example of a game board. Some squares may be occupied with blocks. There are two special squares namely the start and the goal, which are not occupied with blocks. (These two squares are distinct.) Once the stone begins to move, it will proceed until it hits a block. In order to bring the stone to the goal, you may have to stop the stone by hitting it against a block, and throw again.


Fig. 1: Example of board (S: start, G: goal)

The movement of the stone obeys the following rules:

At the beginning, the stone stands still at the start square.
The movements of the stone are restricted to x and y directions. Diagonal moves are prohibited.
When the stone stands still, you can make it moving by throwing it. You may throw it to any direction unless it is blocked immediately(Fig. 2(a)).
Once thrown, the stone keeps moving to the same direction until one of the following occurs:
The stone hits a block (Fig. 2(b), (c)).
The stone stops at the square next to the block it hit.
The block disappears.
The stone gets out of the board.
The game ends in failure.
The stone reaches the goal square.
The stone stops there and the game ends in success.
You cannot throw the stone more than 10 times in a game. If the stone does not reach the goal in 10 moves, the game ends in failure.

Fig. 2: Stone movements

Under the rules, we would like to know whether the stone at the start can reach the goal and, if yes, the minimum number of moves required.

With the initial configuration shown in Fig. 1, 4 moves are required to bring the stone from the start to the goal. The route is shown in Fig. 3(a). Notice when the stone reaches the goal, the board configuration has changed as in Fig. 3(b).


Fig. 3: The solution for Fig. D-1 and the final board configuration

Input

The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. The number of datasets never exceeds 100.

Each dataset is formatted as follows.

the width(=w) and the height(=h) of the board 
First row of the board 
... 
h-th row of the board

The width and the height of the board satisfy: 2 <= w <= 20, 1 <= h <= 20.

Each line consists of w decimal numbers delimited by a space. The number describes the status of the corresponding square.

0	vacant square
1	block
2	start position
3	goal position
The dataset for Fig. D-1 is as follows:

6 6 
1 0 0 2 1 0 
1 1 0 0 0 0 
0 0 0 0 0 3 
0 0 0 0 0 0 
1 0 0 0 0 1 
0 1 1 1 1 1

Output

For each dataset, print a line having a decimal integer indicating the minimum number of moves along a route from the start to the goal. If there are no such routes, print -1 instead. Each line should not have any character other than this number.

Sample Input

2 1
3 2
6 6
1 0 0 2 1 0
1 1 0 0 0 0
0 0 0 0 0 3
0 0 0 0 0 0
1 0 0 0 0 1
0 1 1 1 1 1
6 1
1 1 2 1 1 3
6 1
1 0 2 1 1 3
12 1
2 0 1 1 1 1 1 1 1 1 1 3
13 1
2 0 1 1 1 1 1 1 1 1 1 1 3
0 0
Sample Output

1
4
-1
4
10
-1

个人理解:该题不会写,参照百度答案自己打出来的


代码:

#include<iostream>  
using namespace std;  
  
const int inf=11;  
  
typedef class  
{  
    public:  
        int r,c;     //冰壶当前位置  
        bool status; //status冰壶当前状态:运动true ,静止false  
}SE;  
  
SE s,e;   //记录冰壶起止点  
int w,h;  //场地size  
int MinStep;  //最短路  
int board[30][30];  //场地  
  
void DFS(int i,int j,bool status,int direction,int step,bool flag)    
{ //direction:冰壶当前运动方向  North:0  West:1  South:2  East:3   
  //flag:是否消除direction方向下一格位置的石头  
  
    if(step>10)   //剪枝,超过10步的走法就不再考虑了  
        return;  
  
    if(board[i][j]==3)   //终点  
    {  
        if(MinStep>step)  
            MinStep=step;  
        return;  
    }  
  
    if(flag)  //消除石头  
    {  
        switch(direction)  
        {  
            case 0: {board[i-1][j]=0; break;}  
            case 1: {board[i][j-1]=0; break;}  
            case 2: {board[i+1][j]=0; break;}  
            case 3: {board[i][j+1]=0; break;}  
        }  
    }  
      
    if(!status)  //静止  
    {  
        if(i-1>=1 && (board[i-1][j]==0 || board[i-1][j]==3))  //North  
            DFS(i-1,j,true,0,step+1,false);  
  
        if(j-1>=1 && (board[i][j-1]==0 || board[i][j-1]==3))  //West  
            DFS(i,j-1,true,1,step+1,false);  
  
        if(i+1<=h && (board[i+1][j]==0 || board[i+1][j]==3))  //South  
            DFS(i+1,j,true,2,step+1,false);  
  
        if(j+1<=w && (board[i][j+1]==0 || board[i][j+1]==3))  //East  
            DFS(i,j-1,true,3,step+1,false);  
    }  
    else if(status)  //运动  
    {  
        switch(direction)  
        {  
            case 0:  
                {  
                    if(i-1<1)  //预判下一步是否越界  
                        return;  
                    else  
                    {  
                        if(board[i-1][j]==0)          //下一位置为0且不越界,继续运动  
                            DFS(i-1,j,true,0,step,false);  
                        else if(board[i-1][j]==1)          //下一位置为1且不越界,停止运动,并消除下一位置的石头  
                            DFS(i,j,false,0,step,true);  
                        else if(board[i-1][j]==3)          //下一位置为3且不越界,运动到位置3后停止运动,游戏结束  
                            DFS(i-1,j,false,0,step,false);  
                    }  
  
                    break;  
                }  
            case 1:  
                {  
                    if(j-1<1)  //预判下一步是否越界  
                        return;  
                    else  
                    {  
                        if(board[i][j-1]==0)          //下一位置为0且不越界,继续运动  
                            DFS(i,j-1,true,1,step,false);  
                        else if(board[i][j-1]==1)          //下一位置为1且不越界,停止运动,并消除下一位置的石头  
                            DFS(i,j,false,1,step,true);  
                        else if(board[i][j-1]==3)          //下一位置为3且不越界,运动到位置3后停止运动,游戏结束  
                            DFS(i,j-1,false,1,step,false);  
                    }  
  
                    break;  
                }  
            case 2:  
                {  
                    if(i+1>h)  //预判下一步是否越界  
                        return;  
                    else  
                    {  
                        if(board[i+1][j]==0)          //下一位置为0且不越界,继续运动  
                            DFS(i+1,j,true,2,step,false);  
                        else if(board[i+1][j]==1)          //下一位置为1且不越界,停止运动,并消除下一位置的石头  
                            DFS(i,j,false,2,step,true);  
                        else if(board[i+1][j]==3)          //下一位置为3且不越界,运动到位置3后停止运动,游戏结束  
                            DFS(i+1,j,false,2,step,false);  
                    }  
  
                    break;  
                }  
            case 3:  
                {  
                    if(j+1>w)  //预判下一步是否越界  
                        return;  
                    else  
                    {  
                        if(board[i][j+1]==0)          //下一位置为0且不越界,继续运动  
                            DFS(i,j+1,true,3,step,false);  
                        else if(board[i][j+1]==1)          //下一位置为1且不越界,停止运动,并消除下一位置的石头  
                            DFS(i,j,false,3,step,true);  
                        else if(board[i][j+1]==3)          //下一位置为3且不越界,运动到位置3后停止运动,游戏结束  
                            DFS(i,j+1,false,3,step,false);  
                    }  
  
                    break;  
                }  
        }  
    }  
  
    if(flag)  //回溯前还原石头,即还原上一步的棋盘状态  
    {  
        switch(direction)  
        {  
            case 0: {board[i-1][j]=1; break;}  
            case 1: {board[i][j-1]=1; break;}  
            case 2: {board[i+1][j]=1; break;}  
            case 3: {board[i][j+1]=1; break;}  
        }  
    }  
  
    return;  
}  
  
int main(void)  
{  
    while(cin>>w>>h)  
    {  
        if(!w && !h)  
            break;  
  
        /*Structure the Board*/  
  
        MinStep=inf;  
          
        for(int i=1;i<=h;i++)  
            for(int j=1;j<=w;j++)  
            {  
                cin>>board[i][j];  
  
                if(board[i][j]==2)  
                {  
                    s.r=i;  
                    s.c=j;  
                    s.status=false;  
                    board[i][j]=0;  //记录起点位置后,把它作为0处理  
                }  
                if(board[i][j]==3)  //终点是特别位置,冰壶经过或到达该格都会停止  
                {  
                    e.r=i;  
                    e.c=j;  
                }  
            }  
  
        /*Search the min path*/  
  
        DFS(s.r , s.c , s.status , 0 , 0 , false);  
  
        if(MinStep<=10)  
            cout<<MinStep<<endl;   //DFS里面虽然剪枝了,但是可能把全部走法都剪了,因此还是要判断  
        else  
            cout<<-1<<endl;  
  
    }  
    return 0;  
}  


内容概要:本文详细介绍了扫描单分子定位显微镜(scanSMLM)技术及其在三维超分辨体积成像中的应用。scanSMLM通过电调透镜(ETL)实现快速轴向扫描,结合4f检测系统将不同焦平面的荧光信号聚焦到固定成像面,从而实现快速、大视场的三维超分辨成像。文章不仅涵盖了系统硬件的设计与实现,还提供了详细的软件代码实现,包括ETL控制、3D样本模拟、体积扫描、单分子定位、3D重建和分子聚类分析等功能。此外,文章还比较了循环扫描与常规扫描模式,展示了前者在光漂白效应上的优势,并通过荧光珠校准、肌动蛋白丝、线粒体网络和流感A病毒血凝素(HA)蛋白聚类的三维成像实验,验证了系统的性能和应用潜力。最后,文章深入探讨了HA蛋白聚类与病毒感染的关系,模拟了24小时内HA聚类的动态变化,提供了从分子到细胞尺度的多尺度分析能力。 适合人群:具备生物学、物理学或工程学背景,对超分辨显微成像技术感兴趣的科研人员,尤其是从事细胞生物学、病毒学或光学成像研究的科学家和技术人员。 使用场景及目标:①理解和掌握scanSMLM技术的工作原理及其在三维超分辨成像中的应用;②学习如何通过Python代码实现完整的scanSMLM系统,包括硬件控制、图像采集、3D重建和数据分析;③应用于单分子水平研究细胞内结构和动态过程,如病毒入侵机制、蛋白质聚类等。 其他说明:本文提供的代码不仅实现了scanSMLM系统的完整工作流程,还涵盖了多种超分辨成像技术的模拟和比较,如STED、GSDIM等。此外,文章还强调了系统在硬件改动小、成像速度快等方面的优势,为研究人员提供了从理论到实践的全面指导。
内容概要:本文详细介绍了基于Seggiani提出的渣层计算模型,针对Prenflo气流床气化炉中炉渣的积累和流动进行了模拟。模型不仅集成了三维代码以提供气化炉内部的温度和浓度分布,还探讨了操作条件变化对炉渣行为的影响。文章通过Python代码实现了模型的核心功能,包括炉渣粘度模型、流动速率计算、厚度更新、与三维模型的集成以及可视化展示。此外,还扩展了模型以考虑炉渣组成对特性的影响,并引入了Bingham流体模型,更精确地描述了含未溶解颗粒的熔渣流动。最后,通过实例展示了氧气-蒸汽流量增加2%时的动态响应,分析了温度、流动特性和渣层分布的变化。 适合人群:从事煤气化技术研究的专业人士、化工过程模拟工程师、以及对工业气化炉操作优化感兴趣的科研人员。 使用场景及目标:①评估不同操作条件下气化炉内炉渣的行为变化;②预测并优化气化炉的操作参数(如温度、氧煤比等),以防止炉渣堵塞;③为工业气化炉的设计和操作提供理论支持和技术指导。 其他说明:该模型的实现基于理论公式和经验数据,为确保模型准确性,实际应用中需要根据具体气化炉的数据进行参数校准。模型还考虑了多个物理场的耦合,包括质量、动量和能量守恒方程,能够模拟不同操作条件下的渣层演变。此外,提供了稳态求解器和动态模拟工具,可用于扰动测试和工业应用案例分析。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值