哈理工软件学院"兆方美迪"杯第六届程序设计大赛【高年级组】--决赛 Problem G:逃脱 By Assassin
2016-11-21 11:05
429 查看
思路:需要主要注意到几个关键点
1.正常的小孩是走不了墙壁的。
2.火焰是可以烧掉墙壁的,换句话说火焰必定每次可以向八个方向走一格。
3.注意小朋友先走,火焰后烧过来,就是小朋友行动比火焰快(这个会影响最后一步,小孩的极限逃脱)
那么怎么实现,我的思路是
1.一个数组bfs记录一下火焰第几步烧到某个位置。(这里不这么做也行,因为直接是可以算出来的)
2.小孩儿走,注意小孩的步数应该小于火焰的步数!否则被烧到了!但是存在一种特判,就是最后一步小孩走到了出口,但是火焰刚刚烧到出口,这个情况是可以允许的!需要特判!然后就是限定条件的bfs了,没啥技术难度,主要是细节复杂。
上我的丑代码:
1.正常的小孩是走不了墙壁的。
2.火焰是可以烧掉墙壁的,换句话说火焰必定每次可以向八个方向走一格。
3.注意小朋友先走,火焰后烧过来,就是小朋友行动比火焰快(这个会影响最后一步,小孩的极限逃脱)
那么怎么实现,我的思路是
1.一个数组bfs记录一下火焰第几步烧到某个位置。(这里不这么做也行,因为直接是可以算出来的)
2.小孩儿走,注意小孩的步数应该小于火焰的步数!否则被烧到了!但是存在一种特判,就是最后一步小孩走到了出口,但是火焰刚刚烧到出口,这个情况是可以允许的!需要特判!然后就是限定条件的bfs了,没啥技术难度,主要是细节复杂。
上我的丑代码:
#include<bits/stdc++.h> #define input freopen("input.txt","r",stdin) using namespace std; int n,m; char c[32][32]; int fire[32][32],road[32][32],v[32][32]; int firedir[8][2]={-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1},poepledir[4][2]={-1,0,0,-1,0,1,1,0}; queue<int>t,x,y; void clearn(){ while(!t.empty()){ t.pop(); } while(!x.empty()){ x.pop(); } while(!y.empty()){ y.pop(); } } int inrange(int xxx,int yyy){ if(xxx>0&&xxx<=n&&yyy>0&&yyy<=m)return 1; return 0; } void makefire(int xxx,int yyy,int ttt){ int i,j; for(i=0;i<8;i++){ if(inrange(xxx+firedir[i][0],yyy+firedir[i][1])&&fire[xxx+firedir[i][0]][yyy+firedir[i][1]]==0){ x.push(xxx+firedir[i][0]); y.push(yyy+firedir[i][1]); t.push(ttt+1); fire[xxx+firedir[i][0]][yyy+firedir[i][1]]=ttt+1; } } int xx,yy,tt; while(!x.empty()){ xx=x.front();x.pop(); yy=y.front();y.pop(); tt=t.front();t.pop(); makefire(xx,yy,tt); } } void walk(int xxx,int yyy,int ttt){ int i,j; for(i=0;i<4;i++){ if(inrange(xxx+poepledir[i][0],yyy+poepledir[i][1])&&road[xxx+poepledir[i][0]][yyy+poepledir[i][1]]==0&&(ttt+1<fire[xxx+poepledir[i][0]][yyy+poepledir[i][1]]||(c[xxx+poepledir[i][0]][yyy+poepledir[i][1]]=='E'&&ttt+1==fire[xxx+poepledir[i][0]][yyy+poepledir[i][1]]))&&c[xxx+poepledir[i][0]][yyy+poepledir[i][1]]!='#'){ x.push(xxx+poepledir[i][0]); y.push(yyy+poepledir[i][1]); t.push(ttt+1); road[xxx+poepledir[i][0]][yyy+poepledir[i][1]]=ttt+1; } } int xx,yy,tt; while(!x.empty()){ xx=x.front();x.pop(); yy=y.front();y.pop(); tt=t.front();t.pop(); walk(xx,yy,tt); } } int main(){ //input; int aaa,i,j,startx,starty,outx,outy,firex,firey; scanf("%d",&aaa); while(aaa--){ memset(fire,0,sizeof(fire)); memset(road,0,sizeof(road)); scanf("%d%d",&n,&m); getchar(); for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ scanf("%c",&c[i][j]); if(c[i][j]=='S'){ startx=i; starty=j; } else if(c[i][j]=='*'){ firex=i; firey=j; } else if(c[i][j]=='E'){ outx=i; outy=j; } } getchar(); } memset(v,0,sizeof(v)); clearn(); fire[firex][firey]=-1; makefire(firex,firey,0); clearn(); road[startx][starty]=-1; walk(startx,starty,0); if(road[outx][outy]>0){ cout<<road[outx][outy]<<endl; } else{ cout<<"T_T"<<endl; } } return 0; }
相关文章推荐
- 哈理工软件学院"兆方美迪"杯第六届程序设计大赛【高年级组】--决赛 Problem F: 苦逼的单身狗 By Assassin
- 哈理工软件学院"兆方美迪"杯第六届程序设计大赛【高年级组】--决赛 Problem D: 经商 By Assassin
- 哈理工软件学院"兆方美迪"杯第六届程序设计大赛【高年级组】--决赛 Problem A:凌波微步 By Assassin
- 哈理工软件学院"兆方美迪"杯第六届程序设计大赛【高年级组】--决赛 题解
- 哈理工软件学院"兆方美迪"杯第六届程序设计大赛【高年级组】--决赛(离官方最近的题解)
- 南京林业大学“未来之星”第六届程序设计大赛(决赛)试题A 参考代码
- 哈理工第六届程序设计大赛 G 逃脱(BFS)
- 南京林业大学“未来之星”第六届程序设计大赛(决赛)试题B 参考代码
- 南京林业大学“未来之星”第六届程序设计大赛(决赛)试题D 参考代码
- 南京林业大学“未来之星”第六届程序设计大赛(决赛)试题E 参考代码
- 南京林业大学“未来之星”第六届程序设计大赛(决赛)试题F 参考代码
- 南京林业大学“未来之星”第六届程序设计大赛(决赛)试题G 参考代码
- 湖南省第六届大学生程序设计大赛原题 F Biggest Number (UVA1182)
- 第四届吉林省大学生程序设计大赛个人解题报告 Problem A: Harshad Number
- 2017"百度之星"程序设计大赛 - 资格赛-1003-度度熊与邪恶大魔王
- 2017"百度之星"程序设计大赛 - 资格赛:1002 度度熊的王国战略
- 2017"百度之星"程序设计大赛 - 资格赛 HDU 6083 度度熊的午饭时光
- 2017"百度之星"程序设计大赛-资格赛
- Hdu6108 小C的倍数问题(2017"百度之星"程序设计大赛 - 初赛(A))
- 2017"百度之星"程序设计大赛 - 初赛-度度熊的01世界