C++大炮打蚊子
#include <iostream>
#include <vector>
using namespace std;
struct Mosquito {
int x;
int y;
int life;
};
int shoot(vector<Mosquito>& mos, int x, int y) {
int count = 0;
for (int i = 0; i < mos.size(); i++) {
if (mos[i].life > 0) {
if (mos[i].x == x && mos[i].y == y) {
count++;
mos[i].life = 0;
} else if (abs(mos[i].x - x) + abs(mos[i].y - y) == 1) {
mos[i].life--;
if (mos[i].life == 0) {
count++;
}
}
}
}
return count;
}
int main() {
int m, n;
cin >> m >> n;
vector<Mosquito> mos;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
char c;
cin >> c;
if (c == '#') {
Mosquito m;
m.x = i;
m.y = j;
m.life = 2;
mos.push_back(m);
}
}
}
int k;
cin >> k;
while (k--) {
int x, y;
cin >> x >> y;
int count = shoot(mos, x, y);
cout << count << endl;
}
return 0;
}