恶心的模拟题,不多说
const int N = 30, dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
struct Ant {
int x, y, lx, ly;
int age, life, blood, level;
bool cake;
friend bool operator<(Ant a, Ant b) {
return a.age > b.age;
}
} ant[N];
struct Node {
int x, y;
} Dat[N];
int n, m, S, d, r, num, borned, T;
int flag[N][N], Cnt[N][N], tot;
inline void Input() {
scanf("%d%d", &n, &m);
scanf("%d%d%d", &S, &d, &r);
clr(flag, 0);
Rep(i, S) scanf("%d%d", &Dat[i].x, &Dat[i].y), flag[Dat[i].x][Dat[i].y] = 1;
scanf("%d", &T);
num = tot = 0, clr(Cnt, 0);
}
inline bool Check(int x, int y) {
if(x < 0 || y < 0 || y > m || x > n || flag[x][y]) return 0;
Rep(i, num)
if(ant[i].x == x && ant[i].y == y) return 0;
return 1;
}
inline int Get(int x, int y, int pos, int lx, int ly) {
int a[4], flag = 0, ret = 0;
clr(a, 255);
Rep(i, 4)
if(Check(x + dx[i], y + dy[i]) && !(x + dx[i] == lx && y + dy[i] == ly))
flag = 1, a[i] = Cnt[x + dx[i]][y + dy[i]];
if(!flag) return 4;
For(i, 1, 3)
if(a[i] > a[ret]) ret = i;
if((ant[pos].age + 1) % 5 == 0)
For(i, 1, 4) {
int T = (ret - i + 8) % 4;
if(a[T] != -1) return T;
}
return ret;
}
#define Dist(Ox1, Oy1, Ox2, Oy2) ((Ox1 - Ox2) * (Ox1 - Ox2) + (Oy1 - Oy2) * (Oy1 - Oy2))
struct Point {
DB x, y;
Point() {}
Point(DB _x, DB _y) : x(_x), y(_y) {}
} ;
inline Point operator +(Point a, Point b) { return Point(a.x + b.x, a.y + b.y); }
inline Point operator -(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); }
inline Point operator *(Point a, DB t) { return Point(a.x * t, a.y * t); }
inline DB area(Point a, Point b, Point c) { return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y); }
inline Point Ins(Point a, Point b, Point c, Point d) { return a + ((b - a) * (area(a, c, d) / (area(a, c, b) + area(a, b, d)))); }
inline int Get_Beat(int x, int y) {
if(tot)
Rep(i, num)
if(ant[i].cake && Dist(x, y, ant[i].x, ant[i].y) <= r * r) return i;
int temp = 0x7fffff, ret = 0x7fffff;
Rep(i, num) {
int dist = Dist(x, y, ant[i].x, ant[i].y);
if(dist <= sqr(r) && dist < temp) temp = dist, ret = i;
}
return ret;
}
inline bool Online(Point A, Point P, Point Q) {
if(P.x == Q.x) P.x = P.y, Q.x = Q.y, A.x = A.y;
DB mi = min(P.x, Q.x), ma = max(P.x, Q.x);
return(A.x <= ma && A.x >= mi);
}
inline bool cmp(Ant a, Ant b) { return a.life > b.life; }
inline bool Judge() {
Rep(i, num)
if(ant[i].x == 0 && ant[i].y == 0 && ant[i].cake)
return 1;
return 0;
}
inline void Ant_Born(int now) {
if(num < 6 && Check(0, 0)) {
int kth = borned++ / 6 + 1;
DB life = 4;
Rep(i, kth) life *= 1.1;
ant[num].x = ant[num].y = ant[num].age = ant[num].cake = 0;
ant[num].lx = ant[num].ly = 0, ant[num].level = kth;
ant[num].life = ant[num].blood =(int) life;
num++;
}
}
inline void Ant_Move(int now) {
Rep(i, num) Cnt[ant[i].x][ant[i].y] += ant[i].cake ? 5 : 2;
Rep(i, num) {
int dic = Get(ant[i].x, ant[i].y, i, ant[i].lx, ant[i].ly);
if(dic != 4) {
ant[i].lx = ant[i].x, ant[i].ly = ant[i].y;
ant[i].x += dx[dic], ant[i].y += dy[dic];
} else ant[i].lx = ant[i].x, ant[i].ly = ant[i].y;
if(ant[i].x == n && ant[i].y == m && !tot) {
tot = 1, ant[i].cake = 1;
ant[i].life += ant[i].blood / 2;
ant[i].life = min(ant[i].life, ant[i].blood);
}
}
}
inline void Ant_Beat() {
Rep(i, S) {
int c = Get_Beat(Dat[i].x, Dat[i].y);
if(c < 0x7ffff) {
Point P, Q, T;
P = Point(Dat[i].x, Dat[i].y), Q = Point(ant[c].x, ant[c].y);
T = P - Q;
swap(T.x, T.y);
T.y = - T.y;
Rep(j, num)
if(j == c) ant[j].life -= d;
else {
Point OO, R, I;
OO = Point((DB)ant[j].x, (DB)ant[j].y);
R = OO + T, I = Ins(OO, R, P, Q);
if(Dist(OO.x, OO.y, I.x, I.y) <= 0.25 && Online(I, P, Q)) ant[j].life -= d;
}
}
}
sort(ant, ant + num, cmp);
while(ant[num - 1].life < 0)
if(ant[--num].cake) tot = 0;
sort(ant, ant + num);
}
inline void Solve() {
For(i, 1, T) {
Ant_Born(i), Ant_Move(i), Ant_Beat();
if(Judge()) {
printf("Game over after %d seconds\n%d\n", i, num);
Rep(i, num) printf("%d %d %d %d %d\n", ant[i].age, ant[i].level, ant[i].life, ant[i].x, ant[i].y);
return;
}
Rep(i, num) ant[i].age++;
For(i, 0, n)
For(j, 0, m) Cnt[i][j] = max(Cnt[i][j] - 1, 0);
}
printf("The game is going on\n%d\n", num);
Rep(i, num) printf("%d %d %d %d %d\n", ant[i].age, ant[i].level, ant[i].life, ant[i].x, ant[i].y);
}
int main() {
Input();
Solve();
return 0;
}