BFS POJ3322 Bloxorz I

Bloxorz I
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 6108 Accepted: 2007

Description

Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' which makes him excited. It's a game about rolling a box to a specific position on a special plane. Precisely, the plane, which is composed of several unit cells, is a rectangle shaped area. And the box, consisting of two perfectly aligned unit cube, may either lies down and occupies two neighbouring cells or stands up and occupies one single cell. One may move the box by picking one of the four edges of the box on the ground and rolling the box 90 degrees around that edge, which is counted as one move. There are three kinds of cells, rigid cells, easily broken cells and empty cells. A rigid cell can support full weight of the box, so it can be either one of the two cells that the box lies on or the cell that the box fully stands on. A easily broken cells can only support half the weight of the box, so it cannot be the only cell that the box stands on. An empty cell cannot support anything, so there cannot be any part of the box on that cell. The target of the game is to roll the box standing onto the only target cell on the plane with minimum moves.


The box stands on a single cell

The box lies on two neighbouring cells, horizontally

The box lies on two neighbouring cells, vertically

After Little Tom passes several stages of the game, he finds it much harder than he expected. So he turns to your help.

Input

Input contains multiple test cases. Each test case is one single stage of the game. It starts with two integers R and C(3 ≤ R, C ≤ 500) which stands for number of rows and columns of the plane. That follows the plane, which contains R lines and C characters for each line, with 'O' (Oh) for target cell, 'X' for initial position of the box, '.' for a rigid cell, '#' for a empty cell and 'E' for a easily broken cell. A test cases starts with two zeros ends the input.

It guarantees that

  • There's only one 'O' in a plane.
  • There's either one 'X' or neighbouring two 'X's in a plane.
  • The first(and last) row(and column) must be '#'(empty cell).
  • Cells covered by 'O' and 'X' are all rigid cells.

Output

For each test cases output one line with the minimum number of moves or "Impossible" (without quote) when there's no way to achieve the target cell.  

Sample Input

7 7
#######
#..X###
#..##O#
#....E#
#....E#
#.....#
#######
0 0

Sample Output

10

好久没有写blog了,今天spli写这个题,他竟然自嘲自己代码丑,真是扯,我的才丑呢!

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<queue>
 6 using namespace std;
 7 int n,m,endx,endy;
 8 char ch[510][510];
 9 bool check[510][510][3];
10 int dx0[4]={1,-2,0,0},dy0[4]={0,0,1,-2},ds0[4]={1,1,2,2},dx1[4]={2,-1,0,0},dy1[4]={0,0,1,-1},ds1[4]={0,0,1,1},dx2[4]={1,-1,0,0},dy2[4]={0,0,-1,2},ds2[4]={2,2,0,0};
11 struct data{
12     int x,y,cnt,state;
13 };
14 queue<data>q;
15 void prework(){
16     endx=0,endy=0;
17     memset(check,0,sizeof(check));
18     while(!q.empty()) q.pop();
19     for(int i=1;i<=n;i++) scanf("%s",&ch[i]+1);
20     for(int i=1;i<=n;i++)
21         for(int j=1;j<=m;j++){
22             if(ch[i][j]=='O') endx=i,endy=j;
23             if(ch[i][j]=='#'){
24                 check[i][j][0]=1,check[i][j][1]=1,check[i][j][2]=1;
25                 if(i>=2) check[i-1][j][1]=1;
26                 if(j>=2) check[i][j-1][2]=1;
27             }
28             if(ch[i][j]=='X'){
29                 bool flag=0;
30                 if(ch[i+1][j]=='X') q.push((data){i,j,0,1}),check[i][j][1]=1,flag=1;
31                 if(ch[i][j+1]=='X') q.push((data){i,j,0,2}),check[i][j][2]=1,flag=1;
32                 if(!flag) q.push((data){i,j,0,0}),check[i][j][0]=1;
33             }
34         }
35 }
36 void bfs(){
37     while(!q.empty()){
38         data p=q.front();
39         q.pop();
40         if((p.x<1||p.x>n||p.y<1||p.y>m)||(!p.state&&ch[p.x][p.y]=='E')||(p.state==1&&p.x+1>n)||(p.state==2&&p.y+1>m)) continue;
41         if(p.x==endx&&p.y==endy&&!p.state){
42             printf("%d\n",p.cnt);
43             return;
44         }
45         if(!p.state)
46             for(int i=0;i<=3;i++)
47                 if(!check[p.x+dx0[i]][p.y+dy0[i]][ds0[i]]&&p.x+dx0[i]>=1&&p.x+dx0[i]<=n&&p.y+dy0[i]>=1&&p.y+dy0[i]<=m) q.push((data){p.x+dx0[i],p.y+dy0[i],p.cnt+1,ds0[i]}),check[p.x+dx0[i]][p.y+dy0[i]][ds0[i]]=1;
48         if(p.state==1){
49             for(int i=0;i<=1;i++) 
50                 if(!check[p.x+dx1[i]][p.y+dy1[i]][ds1[i]]&&p.x+dx1[i]>=1&&p.x+dx1[i]<=n&&p.y+dy1[i]>=1&&p.y+dy1[i]<=m&&ch[p.x+dx1[i]][p.y+dy1[i]]!='E') q.push((data){p.x+dx1[i],p.y+dy1[i],p.cnt+1,ds1[i]}),check[p.x+dx1[i]][p.y+dy1[i]][ds1[i]]=1;
51             for(int i=2;i<=3;i++) 
52                 if(!check[p.x+dx1[i]][p.y+dy1[i]][ds1[i]]&&p.x+dx1[i]>=1&&p.x+dx1[i]<=n&&p.y+dy1[i]>=1&&p.y+dy1[i]<=m) q.push((data){p.x+dx1[i],p.y+dy1[i],p.cnt+1,ds1[i]}),check[p.x+dx1[i]][p.y+dy1[i]][ds1[i]]=1;
53         }
54         if(p.state==2){
55             for(int i=0;i<=1;i++) 
56                 if(!check[p.x+dx2[i]][p.y+dy2[i]][ds2[i]]&&p.x+dx2[i]>=1&&p.x+dx2[i]<=n&&p.y+dy2[i]>=1&&p.y+dy2[i]<=m) q.push((data){p.x+dx2[i],p.y+dy2[i],p.cnt+1,ds2[i]}),check[p.x+dx2[i]][p.y+dy2[i]][ds2[i]]=1;
57             for(int i=2;i<=3;i++) 
58                 if(!check[p.x+dx2[i]][p.y+dy2[i]][ds2[i]]&&p.x+dx2[i]>=1&&p.x+dx2[i]<=n&&p.y+dy2[i]>=1&&p.y+dy2[i]<=m&&ch[p.x+dx2[i]][p.y+dy2[i]]!='E') q.push((data){p.x+dx2[i],p.y+dy2[i],p.cnt+1,ds2[i]}),check[p.x+dx2[i]][p.y+dy2[i]][ds2[i]]=1;
59         }
60     }
61     printf("Impossible\n");
62     return;
63 }
64 int main(){
65     while(scanf("%d%d",&n,&m)&&n&&m){
66         prework();
67         bfs();
68     }
69     return 0;
70 }

 



转载于:https://www.cnblogs.com/sdfzxh/p/7397722.html

主要内容:本文详细介绍了一种QRBiLSTM(分位数回归双向长短期记忆网络)的时间序列区间预测方法。首先介绍了项目背景以及模型的优势,比如能够有效利用双向的信息,并对未来的趋势上限和下限做出估计。接着从数据生成出发讲述了具体的代码操作过程:数据预处理,搭建模型,进行训练,并最终可视化预测结果与计算分位数回归的边界线。提供的示例代码可以完全运行并且包含了数据生成环节,便于新手快速上手,深入学习。此外还指出了模型未来发展的方向,例如加入额外的输入特性和改善超参数配置等途径提高模型的表现。文中强调了时间序列的标准化和平稳检验,在样本划分阶段需要按时间序列顺序进行划分,并在训练阶段采取合适的手段预防过度拟合发生。 适合人群:对于希望学习和应用双向长短时记忆网络解决时序数据预测的初学者和具有一定基础的研究人员。尤其适用于有金融数据分析需求、需要做多一步或多步预测任务的从业者。 使用场景及目标:应用于金融市场波动预报、天气状况变化预测或是物流管理等多个领域内的决策支持。主要目的在于不仅能够提供精确的数值预计还能描绘出相应的区间概率图以增强结论置信程度。 补充说明:本教程通过一个由正弦信号加白噪构造而成的简单实例来指导大家理解和执行QRBiLSTM流程的所有关键步骤,这既方便于初学者跟踪学习,又有利于专业人士作为现有系统的补充参考工具。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值