1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| #include <bits/stdc++.h> using namespace std; struct boss{ int r,c,s,t; }; int main () { int n,m,k; cin>>n>>m>>k; vector<vector<bool>>map(n,vector<bool>(m,false)); vector<boss>boss_message; for (int i = 0; i<k; i++) { int r,c,s,t; cin>>r>>c>>s>>t; boss_message.push_back({r,c,s,t}); map[r][c] = true; } vector<bool>die(k,false); while (true) { bool boss_check = true; for (auto p : die) { if (p == false) { boss_check = false; break; } } if (boss_check) { break; } set<pair<int, int>>bomb; vector<pair<int, int>>locate; for (int i = 0; i<n; i++) { for (int j = 0; j<m; j++) { if (map[i][j] == true) { bomb.insert({i,j}); } } } vector<pair<int, int>>erase; for (int i = 0; i<boss_message.size(); i++) { if (die[i] == true) { locate.push_back({-1,-1}); continue; } int x = boss_message[i].r; int y = boss_message[i].c; bomb.insert({x,y}); int move_x = boss_message[i].s; int move_y = boss_message[i].t; int nx= x+move_x; int ny= y+move_y; if (nx>=0 && ny>= 0 && nx<n && ny<m) { if (!map[nx][ny]) { boss_message[i].r = nx; boss_message[i].c = ny; } else { erase.push_back({nx,ny}); die[i] = true; } } else { die[i] = true; } locate.push_back({nx,ny}); } for (int i = 0; i<locate.size(); i++) { if (locate[i].first == -1 && locate[i].second == -1) { continue; } if (bomb.count({locate[i].first,locate[i].second}) == true) { //bomb.erase(bomb.find(locate[i])); erase.push_back({locate[i]}); die[i] = true; } } for (auto p : erase) { map[p.first][p.second] = false; if (bomb.count(p)) { bomb.erase(p); } } for (auto p : bomb) { map[p.first][p.second] = true; } } int ans = 0; for (int i = 0; i<n; i++) { for (int j = 0; j<m; j++) { if (map[i][j] == true) { ans++; } } } cout<<ans<<endl; return 0; }
|