zoukankan      html  css  js  c++  java
  • hdu 2102

    A计划

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 8327    Accepted Submission(s): 1973


    Problem Description
    可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。
    现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且不需要任何时间。
     
    Input
    输入的第一行C表示共有C个测试数据,每个测试数据的前一行有三个整数N,M,T。 N,M迷宫的大小N*M(1 <= N,M <=10)。T如上所意。接下去的前N*M表示迷宫的第一层的布置情况,后N*M表示迷宫第二层的布置情况。
     
    Output
    如果骑士们能够在T时刻能找到公主就输出“YES”,否则输出“NO”。
     
    Sample Input
     
    题意:这一题要求问在T时刻能否达到,由于路可以反复的走,所以可以理解成在T时刻之前能到达就可以了
         如果题目意思,加上了,走过的路,下一刻就会崩塌,那么,就不行了。那么就比较麻烦了哦。
            这道题,#的设置,要注意可能已传过去就碰到了公主。(⊙o⊙)…
    1
    5 5 14
    S*#*.
    .#...
    .....
    ****.
    ...#.
     
    ..*.P
    #.*..
    ***..
    ...*.
    *.#..
     
    Sample Output
    YES
     
    Source
     
    Recommend
     
     
      1 #include<iostream>
      2 #include<stdio.h>
      3 #include<cstring>
      4 #include<cstdlib>
      5 #include<queue>
      6 #include<cmath>
      7 using namespace std;
      8 
      9 int n,m,ti;
     10 char a[2][12][12];
     11 bool hash[2][22][12];
     12 int map1[4][2]={ {1,0},{0,1},{-1,0},{0,-1}};
     13 struct node
     14 {
     15     int x,y,z;
     16     int time;
     17 };
     18 queue<node>Q;
     19 int bfs(int x,int y,int z)
     20 {
     21     int i,x1,y1,z1;
     22     node t,cur;
     23     t.time=0;
     24     t.x=x;
     25     t.y=y;
     26     t.z=z;
     27     hash[x][y][z]=true;
     28     Q.push(t);
     29 
     30     while(!Q.empty())
     31     {
     32         cur=Q.front();
     33         Q.pop();
     34         if(cur.time>=ti) continue;
     35         for(i=0;i<4;i++)
     36         {
     37             x1=cur.x;
     38             y1=cur.y+map1[i][0];
     39             z1=cur.z+map1[i][1];
     40             if(y1>=0&&y1<n && z1>=0&&z1<m &&a[x1][y1][z1]!='*')
     41             {
     42                 if(a[x1][y1][z1]=='P') return 1;
     43 
     44                 if(a[x1][y1][z1]=='#' && hash[x1][y1][z1]==false)
     45                 {
     46                     x1=(x1+1)%2;
     47                     if(hash[x1][y1][z1]==false)
     48                     {
     49                         hash[x1][y1][z1]=true;
     50                         if(a[x1][y1][z1]=='P') return 1;
     51                         t.x=x1;
     52                         t.y=y1;
     53                         t.z=z1;
     54                         t.time=cur.time+1;
     55                         Q.push(t);
     56                     }
     57                 }
     58                 else if(a[x1][y1][z1]=='.' && hash[x1][y1][z1]==false)
     59                 {
     60                     hash[x1][y1][z1]=true;
     61                     t.x=x1;
     62                     t.y=y1;
     63                     t.z=z1;
     64                     t.time=cur.time+1;
     65                     Q.push(t);
     66                 }
     67             }
     68         }
     69     }
     70     return -1;
     71 }
     72 int main()
     73 {
     74     int T;
     75     int i,j,x,y,z,cur;
     76     scanf("%d",&T);
     77     while(T--)
     78     {
     79         scanf("%d%d%d",&n,&m,&ti);
     80         for(i=0;i<n;i++)
     81             scanf("%s",a[0][i]);
     82         for(i=0;i<n;i++)
     83             scanf("%s",a[1][i]);
     84         x=0;y=0;z=0;
     85         for(i=0;i<n;i++)
     86         {
     87             for(j=0;j<m;j++)
     88             {
     89                 if(a[0][i][j]=='#' && (a[1][i][j]=='*'||a[1][i][j]=='#'))
     90                 {
     91                     a[0][i][j]='*';
     92                     a[1][i][j]='*';
     93                 }
     94                 if(a[0][i][j]=='*' && a[1][i][j]=='#')
     95                 {
     96                     a[1][i][j]='*';
     97                 }
     98                 if(a[0][i][j]=='S'){
     99                     x=0;
    100                     y=i;
    101                     z=j;
    102                 }
    103                 if(a[1][i][j]=='S'){
    104                     x=1;
    105                     y=i;
    106                     z=j;
    107                 }
    108             }
    109         }
    110         memset(hash,false,sizeof(hash));
    111         while(!Q.empty())
    112         {
    113             Q.pop();
    114         }
    115         cur=bfs(x,y,z);
    116         if(cur==1) printf("YES
    ");
    117         else printf("NO
    ");
    118     }
    119     return 0;
    120 }
  • 相关阅读:
    VIJOS-P1340 拯救ice-cream(广搜+优先级队列)
    uva 11754 Code Feat
    uva11426 GCD Extreme(II)
    uvalive 4119 Always an Interger
    POJ 1442 Black Box 优先队列
    2014上海网络赛 HDU 5053 the Sum of Cube
    uvalive 4795 Paperweight
    uvalive 4589 Asteroids
    uvalive 4973 Ardenia
    DP——数字游戏
  • 原文地址:https://www.cnblogs.com/tom987690183/p/3647175.html
Copyright © 2011-2022 走看看