标签:bsp gem mem range namespace nes oid ems desc
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 struct node 5 { 6 int x, y, t; 7 node(int a, int b, int c) 8 { 9 x = a, y = b, t = c; 10 } 11 }; 12 13 char mp[203][203]; 14 int arr[203][203], may[203][203]; 15 bool mk[203][203]; 16 int dir[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; 17 18 void bfs(int bgx, int bgy) 19 { 20 memset(mk, false, sizeof(mk)); 21 queue<node> que; 22 que.push(node(bgx, bgy, 0)); 23 mk[bgx][bgy] = true; 24 while( !que.empty()) 25 { 26 node f = que.front(); 27 que.pop(); 28 for(int i=0; i<4; ++ i) 29 { 30 int x = f.x + dir[i][0], y = f.y + dir[i][1]; 31 int t = f.t + 1; 32 if(mp[x][y] != ‘#‘ && mk[x][y] == false) 33 { 34 mk[x][y] = true; 35 if(mp[x][y] == ‘@‘) 36 arr[x][y] += t, may[x][y] += 1; 37 que.push(node(x, y, t)); 38 } 39 } 40 } 41 } 42 int main() 43 { 44 int n, m; 45 while(scanf("%d%d", &n, &m) != EOF) 46 { 47 int y_bgx, y_bgy, m_bgx, m_bgy; 48 memset(mp, ‘#‘, sizeof(mp)); 49 for(int i=1; i<=n; ++ i) 50 { 51 for(int j=1; j<=m; ++ j) 52 { 53 scanf(" %c", &mp[i][j]); 54 if(mp[i][j] == ‘Y‘) 55 y_bgx = i, y_bgy = j; 56 if(mp[i][j] == ‘M‘) 57 m_bgx = i, m_bgy = j; 58 } 59 } 60 memset(arr, 0, sizeof(arr)); 61 memset(may, 0, sizeof(may)); 62 63 bfs(y_bgx, y_bgy); 64 bfs(m_bgx, m_bgy); 65 int ans = 1000000; 66 for(int i=1; i<=n; ++ i) 67 { 68 for(int j=1; j<=m; ++ j) 69 { 70 if(mp[i][j] == ‘@‘ && may[i][j] == 2) 71 { 72 if(arr[i][j] < ans) 73 ans = arr[i][j]; 74 } 75 } 76 } 77 printf("%d\n", ans * 11); 78 } 79 return 0; 80 }
标签:bsp gem mem range namespace nes oid ems desc
原文地址:https://www.cnblogs.com/1625--H/p/9348279.html