研究思路
我第一眼看到题时,感觉是模拟题,所以我就模拟炸弹和僵尸的前进。结果……就过了。
AC Code
#include <bits/stdc++.h>
using namespace std;
struct IO{
void read(char &x){
x = getchar();
while (isspace(x)){
x = getchar();
}
}
void write(char x){
putchar(x);
}
template <typename T>
void read(T& x){
x = 0;
int w = 1;
char c = getchar();
while (!isdigit(c)){
if (c == '-'){
w = -w;
}c = getchar();
}while (isdigit(c)){
x = (x << 1) + (x << 3) + (c ^ '0');
c = getchar();
}if (w == -1){
x = ~(x - 1);
}
}
template <typename T>
void write(T x){
if (x < 0){
putchar('-');
x = -x;
}if (x > 9){
write(x / 10);
}putchar(x % 10 + '0');
}
template <typename T, typename... S>
void read(T& x, S&... xs){
read(x);
read(xs...);
}
template <typename T, typename... S>
void write(T x, S... xs){
write(x);
write(xs...);
}
}io;
#define rep(i, l, r, d) for (int i = (l); i <= (r); i += d)
#define rrep(i, r, l, d) for (int i = (r); i >= (l); i -= d)
int n, m, k, t, res, cntb, cntz;
struct Bomb{
int x, r, t;
}bomb[205];
struct Zombies{
bool die, flag;
int w;
}zombies[205];
bool cmp(Bomb x, Bomb y){
return x.t < y.t;
}
int main(){
io.read(n, m, k);
cntb++;
t = n + m;
rep (i, 1, k, 1){
io.read(bomb[i].x, bomb[i].r, bomb[i].t);
}sort(bomb + 1, bomb + k + 1, cmp);
rep (i, 1, t, 1){
if (i <= m){
zombies[++cntz].w = 0;
}rep (j, 1, cntz, 1){
if (!zombies[j].die && !zombies[j].flag){
zombies[j].w++;
if (zombies[j].w == n + 1){
zombies[j].flag = true;
res++;
}
}
}while (bomb[cntb].t == i){
rep (j, 1, cntz, 1){
if (zombies[j].w && !zombies[j].flag && bomb[cntb].x - bomb[cntb].r <= zombies[j].w && zombies[j].w <= bomb[cntb].x + bomb[cntb].r){
zombies[j].die = true;
}
}cntb++;
}
}io.write(res);
return 0;
}