fork download
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <fstream>
  8.  
  9. #define rep( i, l, r ) for (int i = l; i <= r; i++)
  10. #define down( i, l, r ) for (int i = l; i >= r; i--)
  11. #define MS 123456
  12. #define MAX 1073741823
  13. #define MIN 1E-6
  14. #define Q 100000007
  15.  
  16. using namespace std;
  17.  
  18. struct node
  19. {
  20. int x, y;
  21. } p[23];
  22. struct Animal
  23. {
  24. int x, y, age, hp, maxhp, l, last;
  25. bool cake;
  26. } Ant[234567];
  27. int n, m, s, d, r, T, Now, NowAnt, AllAnt, Map[9][9], Alive[9], Target, Message[9][9], a, x, y, Choose, CM, Nowd;
  28. double AntHp;
  29.  
  30. void IncAnt()
  31. {
  32. if (NowAnt == 6) return;
  33. if (Map[0][0] != 0) return;
  34. NowAnt++; AllAnt++;
  35. if (AllAnt%6 == 1) AntHp *= 1.1;
  36. Ant[AllAnt].x = 0; Ant[AllAnt].y = 0;
  37. Ant[AllAnt].age = 0; Ant[AllAnt].hp = int(AntHp); Ant[AllAnt].maxhp = int(AntHp);
  38. Ant[AllAnt].l = (AllAnt-1)/6+1; Ant[AllAnt].cake = false;
  39. Ant[AllAnt].last = 0;
  40. Alive[NowAnt] = AllAnt;
  41. Map[0][0] = 1;
  42. }
  43.  
  44. void AddMessage()
  45. {
  46. rep(i, 1, NowAnt)
  47. {
  48. a = Alive[i];
  49. if (Ant[a].cake) Message[Ant[a].x][Ant[a].y] += 5; else Message[Ant[a].x][Ant[a].y] += 2;
  50. }
  51. }
  52.  
  53. void Move()
  54. {
  55. rep(i, 1, NowAnt)
  56. {
  57. a = Alive[i]; x = Ant[a].x; y = Ant[a].y;
  58. Choose = 0; CM = -MAX;
  59. if (Ant[a].last != 3 && y < m && CM < Message[x][y+1] && Map[x][y+1] == 0) Choose = 1, CM = Message[x][y+1];
  60. if (Ant[a].last != 4 && x < n && CM < Message[x+1][y] && Map[x+1][y] == 0) Choose = 2, CM = Message[x+1][y];
  61. if (Ant[a].last != 1 && y > 0 && CM < Message[x][y-1] && Map[x][y-1] == 0) Choose = 3, CM = Message[x][y-1];
  62. if (Ant[a].last != 2 && x > 0 && CM < Message[x-1][y] && Map[x-1][y] == 0) Choose = 4, CM = Message[x-1][y];
  63. if ((Ant[a].age+1) % 5 == 0 && Choose != 0)
  64. {
  65. while (true)
  66. {
  67. Choose--;
  68. if (Choose == 0) Choose = 4;
  69. if (Choose == 1 && Ant[a].last != 3 && y < m && Map[x][y+1] == 0) break;
  70. if (Choose == 2 && Ant[a].last != 4 && x < n && Map[x+1][y] == 0) break;
  71. if (Choose == 3 && Ant[a].last != 1 && y > 0 && Map[x][y-1] == 0) break;
  72. if (Choose == 4 && Ant[a].last != 2 && x > 0 && Map[x-1][y] == 0) break;
  73. }
  74. }
  75. Map[x][y] = 0; Ant[a].last = Choose;
  76. if (Choose == 0) Map[x][y] = 1;
  77. if (Choose == 1) Map[x][y+1] = 1, Ant[a].y++;
  78. if (Choose == 2) Map[x+1][y] = 1, Ant[a].x++;
  79. if (Choose == 3) Map[x][y-1] = 1, Ant[a].y--;
  80. if (Choose == 4) Map[x-1][y] = 1, Ant[a].x--;
  81. }
  82. }
  83.  
  84. void MoveCake()
  85. {
  86. rep(i, 1, NowAnt)
  87. {
  88. a = Alive[i];
  89. if (Ant[a].x == n && Ant[a].y == m)
  90. {
  91. Target = a;
  92. Ant[a].cake = true;
  93. Ant[a].hp += Ant[a].maxhp/2; if (Ant[a].hp > Ant[a].maxhp) Ant[a].hp = Ant[a].maxhp;
  94. continue;
  95. }
  96. }
  97. }
  98.  
  99. int sqr(int x) { return x*x; }
  100.  
  101. int Dis(int x1, int y1, int x2, int y2) { return sqr(x1-x2)+sqr(y1-y2); }
  102.  
  103. void FightAnt(int s, int t)
  104. {
  105. int a1, b1, c1, a2, b2, c2;
  106. rep(i, 1, NowAnt)
  107. {
  108. a = Alive[i];
  109. if (a == t)
  110. { Ant[a].hp -= d; continue; }
  111. if (Dis(p[s].x, p[s].y, Ant[a].x, Ant[a].y) <= 0.25)
  112. { Ant[a].hp -= d; continue; }
  113. if (Dis(Ant[t].x, Ant[t].y, Ant[a].x, Ant[a].y) <= 0.25)
  114. { Ant[a].hp -= d; continue; }
  115. if (sqr(abs(p[s].x*Ant[t].y-p[s].x*Ant[a].y+Ant[t].x*Ant[a].y-Ant[t].x*p[s].y+Ant[a].x*p[s].y-Ant[a].x*Ant[t].y)) > Dis(p[s].x, p[s].y, Ant[t].x, Ant[t].y)*0.25) continue;
  116. a1 = p[s].y-Ant[t].y; b1 = Ant[t].x-p[s].x; c1 = -a1*p[s].x-b1*p[s].y; a2 = -b1; b2 = a1; c2 = -a2*Ant[a].x-b2*Ant[a].y;
  117. if (b1 == 0)
  118. {
  119. if ((p[s].y <= Ant[a].y && Ant[a].y <= Ant[t].y) || (Ant[t].y <= Ant[a].y && Ant[a].y <= p[s].y))
  120. { Ant[a].hp -= d; continue; }
  121. }
  122. else if (a1 == 0)
  123. {
  124. if ((p[s].x <= Ant[a].x && Ant[a].x <= Ant[t].x) || (Ant[t].x <= Ant[a].x && Ant[a].x <= p[s].x))
  125. { Ant[a].hp -= d; continue; }
  126. }
  127. else if (a1*b2-a2*b1 > 0)
  128. {
  129. if ((p[s].x*(a1*b2-a2*b1) <= c2*b1-c1*b2 && c2*b1-c1*b2 <= Ant[t].x*(a1*b2-a2*b1)) || (Ant[t].x*(a1*b2-a2*b1) <= c2*b1-c1*b2 && c2*b1-c1*b2 <= p[s].x*(a1*b2-a2*b1)))
  130. { Ant[a].hp -= d; continue; }
  131. }
  132. else
  133. {
  134. if ((p[s].x*(a1*b2-a2*b1) >= c2*b1-c1*b2 && c2*b1-c1*b2 <= Ant[t].x*(a1*b2-a2*b1)) || (Ant[t].x*(a1*b2-a2*b1) >= c2*b1-c1*b2 && c2*b1-c1*b2 <= p[s].x*(a1*b2-a2*b1)))
  135. { Ant[a].hp -= d; continue; }
  136. }
  137. }
  138. }
  139.  
  140. void Fight()
  141. {
  142. rep(i, 1, s)
  143. {
  144. if (Target != 0)
  145. {
  146. Nowd = sqr(Ant[Target].x - p[i].x) + sqr(Ant[Target].y - p[i].y);
  147. if (Nowd <= r)
  148. {
  149. FightAnt(i, Target);
  150. continue;
  151. }
  152. }
  153. Choose = 0; CM = MAX;
  154. rep(j, 1, NowAnt)
  155. {
  156. a = Alive[j];
  157. Nowd = sqr(Ant[a].x - p[i].x) + sqr(Ant[a].y - p[i].y);
  158. if (Nowd < CM) CM = Nowd, Choose = a;
  159. }
  160. if (Choose != 0 && CM <= r) FightAnt(i, Choose);
  161. }
  162. }
  163.  
  164. void PutCake()
  165. {
  166. Ant[Target].cake = false;
  167. Target = 0;
  168. }
  169.  
  170. void DelDie()
  171. {
  172. int i = 0;
  173. while (i < NowAnt)
  174. {
  175. i++;
  176. a = Alive[i];
  177. if (Ant[a].hp < 0)
  178. {
  179. Map[Ant[a].x][Ant[a].y] = 0;
  180. rep(j, i, NowAnt-1) Alive[j] = Alive[j+1];
  181. NowAnt--; i--;
  182. }
  183. }
  184. }
  185.  
  186. void End(bool b)
  187. {
  188. if (b) printf("Game over after %d seconds\n%d\n", Now, NowAnt); else printf("The game is going on\n%d\n", NowAnt);
  189. rep(i, 1, NowAnt)
  190. {
  191. a = Alive[i];
  192. printf("%d %d %d %d %d\n", Ant[a].age, Ant[a].l, Ant[a].hp, Ant[a].x, Ant[a].y);
  193. }
  194. exit(0);
  195. }
  196.  
  197. void DelMessage()
  198. {
  199. rep(i, 0, n) rep(j, 0, m) if (Message[i][j] > 0) Message[i][j]--;
  200. }
  201.  
  202. void AddAge()
  203. {
  204. rep(i, 1, NowAnt) Ant[Alive[i]].age++;
  205. }
  206.  
  207. int main()
  208. {
  209. //freopen("curves.in", "r", stdin);
  210. //freopen("curves.out", "w", stdout);
  211. scanf("%d%d%d%d%d", &n, &m, &s, &d, &r);
  212. rep(i, 1, s) { scanf("%d%d", &p[i].x, &p[i].y); Map[p[i].x][p[i].y] = 2; }
  213. AntHp = 4; r *= r;
  214. scanf("%d", &T);
  215. while (T > Now)
  216. {
  217. Now++;
  218. if (Now == 765)
  219. a = a;
  220. IncAnt();
  221. AddMessage();
  222. Move();
  223. if (Target == 0 && Map[n][m] == 1) MoveCake();
  224. Fight();
  225. if (Target != 0 && Ant[Target].hp < 0) PutCake();
  226. DelDie();
  227. if (Target != 0 && Ant[Target].x == 0 && Ant[Target].y == 0) End(true);
  228. DelMessage();
  229. AddAge();
  230. }
  231.  
  232. End(false);
  233. //fclose(stdin);
  234. //fclose(stdout);
  235. return 0;
  236. }
  237.  
Success #stdin #stdout 0s 10632KB
stdin
8 8
2 10 1
7 8
8 6
5
stdout
The game is going on
5
5 1 4 1 4
4 1 4 0 4
3 1 4 0 3
2 1 4 0 2
1 1 4 0 1