Blue Bridge University Cup 2020 Group B match province simulation game (a) - Maze

Blue Bridge University Cup 2020 Group B match province simulation game (a) - Maze

 

Written by someone else other explanations

Title : There is a  n- ×  labyrinth m, wherein  . represents a space,  * represents an obstacle. In addition, there are  Q Q one-way portal: If the entry cell  (a_i, B_i) ( A I , B I ), it is immediately transferred to the (C_i, D_i) ( C I , D I ). Each point is to ensure that at most one entry portal. 

If the portal ultimately to an obstacle, it will move on the card can not be an obstacle.

Spent inside the transmission portal is  0, can be moved around to four each in the open grid, cost is  1. (Because the internal portal cost is zero, so to compare how much it takes)

If you can not reach the end, output "No solution"

                                                                                                                        

Com array by recording the first few portal, the unique value, find the portal spread of abscissa and ordinate (door [Portal] [0] through the door and door numerical arrays [Portal] [1 ])

 

. 1 #include <bits / STDC ++ H.>. 1
 2  the using  namespace STD;
 . 3  #define LL Long Long
 . 4  #define N 1010
 . 5  #define INF 0x3f3f3f3f
 . 6  char G [N] [ 1010 ]; // map 
. 7  int COM [N ] [N] = { 0 }; // for whether the transfer gate mark 
. 8  int Door [N] [ . 3 ] = { 0 }; // for conveying the recording where door [i] [0] and Door [ i] [1] are used for X, Y 
. 9  int VIS [N] [N]; // if this is to be used when it takes 
10  int dir[2][4] = { -1,+1,0,0,0,0,-1,+1 };
11 int x, y;
12 int n, m;
13 int ans = inf;
14 struct node
15 {
16     int x, y, num;
17 
18 };
19 int bfs(int p, int q)
20 {
21     queue<node>que;
22     node w;
23     w.x = p, w.y = q, w.num = 0;
24     vis[p][q] = 0;
25     que.push(w);
26     while (!que.empty())
27     {
28         node w;
29         w = que.front();
30         que.pop();
31         int pp = w.x, qq = w.y;
32         //cout<<"sjbd  "<<pp<<" "<<qq<<" "<<w.num<<endl;
33         if(pp==x&&qq == return35        {
34y)
              w.num;
 36          }
 37 [          int U = COM [PP] [QQ];
 38 is          // COUT << "U =" << endl << U; 
39          IF (! U = 0 )
 40          {
 41 is              int PPP = Door [U] [ 0 ];
 42 is              int QQQ Door = [U] [ . 1 ];
 43 is              IF (G [PPP] [QQQ] == ' . ' && w.num < VIS [PPP] [QQQ])
 44 is              { // the point is not an obstacle to the transfer and spend relatively small so go 
45                  VIS [ppp] [QQQ] = w.num;
 46                 node e = w;
47                 e.x = ppp, e.y = qqq;
48                 que.push(e);
49             }
50         }
51         else
52         {
53             for (int i = 0; i < 4; i++)
54             {
55                 int xx = w.x+dir[0][i], yy = w.y+dir[1][i];
56                 if (vis[xx][yy]>w.num+1&& g[xx][yy] == '.'&&xx >= 1 && xx <= n && yy >= 1 && yy <= m)
57                 {
58                     // cout << xx << " " << yy << endl;
59                     node e=w;
60                     e.num += 1;
61                     e.x = xx, e.y = yy;
62                     vis[xx][yy] = w.num+1;
63                     que.push(e);
64                 }
65             }
66         }
67 
68     }
69     return inf;
70 }
71 int main()
72 {
73     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
74     fill(vis[0],vis[0]+(N*N),inf);
75     cin >> n >> m;
76     for (int i = 1; i <= n; i++)
77     {
78         for (int j = 1; j <= m; j++)
79             cin >> g[i][j];
80     }
 81      int P;
 82      CIN >> P;
 83      the while (the P-- )
 84      {
 85          int X1, Y1, X2, Y2;
 86          CIN X1 >> X2 >> >> >> Y1 Y2;
 87          COM [X1] [Y1] = P + . 1 ;
 88          // since the P-value does not repeat, can be used to mark whether the portal can be seen while simultaneously transferred to the place where he 
89          Door [P + . 1 ] [ 0 ] = X2;
 90          Door [P + . 1 ] [ . 1 ] = Y2;
 91 is      }
 92      CIN >> >> X y;
93     ans=bfs(1, 1);
94     if(ans!=inf)
95         cout<<ans<<endl;
96     else
97         cout<<"No solution"<<endl;
98     return 0;
99 }

Guess you like

Origin www.cnblogs.com/thief-of-book/p/12236502.html
Recommended