魔兽世界终极版(c++)(java)
不是很熟悉继承,感觉也不是很有必要
所以我只分了武器、武士、司令部和游戏进程类
把 c++ 转成 java,大部分都是一样的,变量的作用域和类型转换上稍微麻烦一些
HashMap 可以替代 c++ 中的 map
对 double 的四舍五入不是非常了解,但是好像 OJ 上都能通过
c++:
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
#include <map> #include <cstdio> #include <vector> #include <iomanip> #include <cstring> #include <iostream> using namespace std; class SAM* C[25][2]; int M, N, R, K, T; int chp[25], flag[25], lastwin[25], win[25]; bool arr[25]; map<string, int> HP, ATK; int offen(int x){ if(flag[x] != -1)return flag[x]; return !(x & 1); } string int2str(int x){ string str = ""; while(x) str = char(x % 10 + '0') + str, x /= 10; return str; } class Weapon{ public: int atk; Weapon(int type, int _atk){ if(type == 0)atk = _atk / 5; if(type == 1)atk = 100; if(type == 2)atk = 3; } }; class SAM{ public: int atk; int hp; int id; int loyalty; int step; string color; string type; double morale; Weapon* wea[3]; SAM(string _color, int _id, string _type, double hhp):color(_color), type(_type), id(_id){ step = morale = 0; loyalty = 100; hp = HP[type]; atk = ATK[type]; memset(wea, 0 ,sizeof(wea)); auto WA = new Weapon(id % 3, atk), WB = new Weapon((id + 1) % 3, atk); if(WA->atk == 0)WA = NULL; if(WB->atk == 0)WB = NULL; if(type == "dragon"){ wea[id % 3] = WA; morale = (double)hhp / HP["dragon"]; } if(type == "ninja")wea[id % 3] = WA, wea[(id + 1) % 3] = WB; if(type == "iceman")wea[id % 3] = WA; if(type == "lion")loyalty = hhp; } operator string(){ return color + ' ' + type + ' ' + int2str(id); } string attr(){ return "with " + int2str(hp) + " elements and force " + int2str(atk); } int getatk(bool); int usesword(bool); }; string Sam_type[2][5] = { {"iceman", "lion", "wolf", "ninja", "dragon"}, {"lion", "dragon", "ninja", "iceman", "wolf"}, }; class HEA{ public: int hp; int Stot; int type; int pos; int rew; string color; HEA(){} HEA(string _color, int _hp):color(_color), hp(_hp){ if(color == "red")type = 0, pos = 0; else type = 1, pos = N + 1; Stot = 0; } void summon(); }H[2]; class Game{ public: int t; void reset(int cas); void turn(); void escape(); void move(); void gethp(); void shoot(); void usebomb(); void war(); void print15(SAM); }game; void Game::reset(int cas){ printf("Case %d:\n", cas); t = 0; for(int i = 0; i <= N + 1; i++){ C[i][0] = C[i][1] = NULL; flag[i] = lastwin[i] = -1; chp[i] = 0; } } void Game::escape(){ for(int i = 0; i <= N + 1; i++) for(int j = 0; j < 2; j++) if(C[i][j] && C[i][j]->loyalty <= 0 && i != H[j ^ 1].pos){ printf("%03d:05 %s ran away\n", game.t / 60, string(*C[i][j]).c_str()), C[i][j] = NULL; } } void Game::move(){ bool end = 0; int d[2] = {-1, 1}; SAM *tmp[25][2] = {NULL}; for(int i = 0; i <= N + 1; i++) for(int j = 0; j < 2; j++){ int u = i + d[j]; if(i == H[j ^ 1].pos)tmp[i][j] = C[i][j]; if(C[u][j]){ if(u < 0 || u > N + 1)continue; SAM *S = C[u][j]; if(!(++S->step & 1) && S->type == "iceman")S->atk += 20, S->hp = max(1, S->hp - 9); tmp[i][j] = S; if(i == H[j ^ 1].pos){ printf("%03d:10 %s reached %s headquarter %s\n", game.t / 60, string(*S).c_str(), H[j ^ 1].color.c_str(), S->attr().c_str()); if(C[i][j]){ printf("%03d:10 %s headquarter was taken\n", game.t / 60, H[j ^ 1].color.c_str()); end = 1; } } else printf("%03d:10 %s marched to city %d %s\n", game.t / 60, string(*S).c_str(), i, S->attr().c_str()); } } for(int i = 0; i <= N + 1; i++) for(int j = 0; j < 2; j++) C[i][j] = tmp[i][j]; if(end)game.t = -1; } void Game::gethp(){ for(int i = 1; i <= N ; i++) for(int j = 0; j < 2; j++) if(C[i][j] && !C[i][j ^ 1]){ H[j].hp += chp[i]; printf("%03d:30 %s earned %d elements for his headquarter\n", game.t / 60, string(*C[i][j]).c_str(), chp[i]); chp[i] = 0; } } void Game::shoot(){ memset(arr, 0, sizeof(arr)); for(int i = 0; i <= N + 1; i++) for(int j = 0; j < 2; j++){ SAM *u = C[i][j], *v = NULL; int p; if(j == 0)p = i + 1; else p = i - 1; if(p >= 0 && p <= N + 1)v = C[p][j ^ 1]; if(!u || !v || !u->wea[2])continue; v->hp -= R; u->wea[2]->atk--; if(!u->wea[2]->atk)u->wea[2] = NULL; if(v->hp > 0)printf("%03d:35 %s shot\n", game.t / 60, string(*u).c_str()); else{ printf("%03d:35 %s shot and killed %s\n", game.t / 60, string(*u).c_str(), string(*v).c_str()); arr[p] = 1; } } } void Game::usebomb(){ for(int i = 1; i <= N; i++){ int p = offen(i); auto &u = C[i][p], &v = C[i][p ^ 1]; if(!u || !v || arr[i])continue; if(v->wea[1] && u->getatk(0) >= v->hp){ printf("%03d:38 %s used a bomb and killed %s\n", game.t / 60, string(*v).c_str(), string(*u).c_str()); u = v = NULL; } else if(u->wea[1] && u->getatk(0) < v->hp && v->getatk(1) >= u->hp && v->type != "ninja"){ printf("%03d:38 %s used a bomb and killed %s\n", game.t / 60, string(*u).c_str(), string(*v).c_str()); u = v = NULL; } } } void fight(int pos, int p, bool defense){ auto &u = C[pos][p], &v = C[pos][p ^ 1]; int tmp = max(0, v->hp); if(u->hp > 0 && v->hp > 0) if(!defense || u->type != "ninja"){ v->hp -= u->getatk(defense); u->usesword(1); if(defense) printf("%03d:40 %s fought back against %s in city %d\n", game.t / 60, string(*u).c_str(), string(*v).c_str(), pos); else printf("%03d:40 %s attacked %s in city %d %s\n", game.t / 60, string(*u).c_str(), string(*v).c_str(), pos, u->attr().c_str()); } if(v->hp <= 0 && u->hp > 0){ if(!arr[pos]) printf("%03d:40 %s was killed in city %d\n", game.t / 60, string(*v).c_str(), pos); win[pos] = p; if(v->type == "lion")u->hp += tmp; if(u->type == "wolf") for(int i = 0; i < 3; i++) if(!u->wea[i])u->wea[i] = v->wea[i]; } } void Game::war(){ memset(win, -1, sizeof(win)); H[0].rew = H[0].hp / 8; H[1].rew = H[1].hp / 8; for(int i = 1; i <= N; i++) if(C[i][0] && C[i][1]){ int p = offen(i); fight(i, p, 0); fight(i, p ^ 1, 1); if(C[i][p]->morale > 0.8 && C[i][p]->hp > 0) printf("%03d:40 %s yelled in city %d\n", game.t / 60, string(*C[i][p]).c_str(), i); if(win[i] != -1){ int w = win[i]; printf("%03d:40 %s earned %d elements for his headquarter\n", game.t / 60, string(*C[i][w]).c_str(), chp[i]); H[w].hp += chp[i]; chp[i] = 0; if(lastwin[i] == w && flag[i] != w){ flag[i] = w; printf("%03d:40 %s flag raised in city %d\n", game.t / 60, H[w].color.c_str(), i); } lastwin[i] = w; } for(int j = 0; j < 2; j++) if(C[i][j]->type == "dragon"){ if(j == win[i])C[i][j]->morale += 0.2; else C[i][j]->morale -= 0.2; } if(C[i][0]->hp > 0 && C[i][1]->hp > 0){ for(int j = 0; j < 2; j++) if(C[i][j]->type == "lion")C[i][j]->loyalty -= K; lastwin[i] = -1; } } for(int i = 1; i <= N; i++) for(int j = 0; j < 2; j++) if(C[i][j] && C[i][j]->hp <= 0)C[i][j] = NULL; for(int i = N; i && H[0].rew; i--) if(win[i] == 0){ H[0].hp -= 8; H[0].rew--; C[i][0]->hp += 8; } for(int i = 1; i <= N && H[1].rew; i++) if(win[i] == 1){ H[1].hp -= 8; H[1].rew--; C[i][1]->hp += 8; } } void Game::turn(){ int M = t % 60; if(M == 0)H[0].summon(), H[1].summon(); if(M == 5)escape(); if(M == 10)move(); if(t == -1)return; if(M == 20)for(int i = 1; i <= N; i++)chp[i] += 10; if(M == 30)gethp(); if(M == 35)shoot(); if(M == 38)usebomb(); if(M == 40)war(); if(M == 50) for(int i = 0; i < 2; i++) printf("%03d:50 %d elements in %s headquarter\n", game.t / 60, H[i].hp, H[i].color.c_str()); if(M == 55){ for(int i = 0; i <= N + 1; i++) if(C[i][0])print15(*C[i][0]); for(int i = 0; i <= N + 1; i++) if(C[i][1])print15(*C[i][1]); } t++; } void Game::print15(SAM S){ printf("%03d:55 %s has ", game.t / 60, string(S).c_str()); if(S.wea[2]){ printf("arrow(%d)", S.wea[2]->atk); if(S.wea[1] || S.wea[0])putchar(','); else putchar('\n'); } if(S.wea[1]){ printf("bomb"); if(S.wea[0])putchar(','); else putchar('\n'); } if(S.wea[0])printf("sword(%d)\n", S.wea[0]->atk); if(!S.wea[0] && !S.wea[1] && !S.wea[2])puts("no weapon"); } int SAM::usesword(bool con){ auto &x = wea[0]; if(!x)return 0; int res = x->atk; if(con){ x->atk = (int)(x->atk * 0.8); if(!x->atk)x = NULL; } return res; } int SAM::getatk(bool defense){ if(defense)return atk / 2 + usesword(0); else return atk + usesword(0); } void HEA::summon(){ string Stype = Sam_type[type][Stot % 5]; if(HP[Stype] <= hp){ hp -= HP[Stype]; Stot++; SAM* S = new SAM(color, Stot, Stype, hp); C[pos][type] = S; printf("%03d:00 %s born\n", game.t / 60, string(*S).c_str()); if(S->type == "dragon") printf("Its morale is %.2lf\n", S->morale); if(S->type == "lion") printf("Its loyalty is %d\n", S->loyalty); } } int main(){ int tot; cin >> tot; for(int cas = 1; cas <= tot; cas++){ cin >> M >> N >> R >> K >> T; game.reset(cas); H[0] = HEA("red", M); H[1] = HEA("blue", M); cin >> HP["dragon"] >> HP["ninja"] >> HP["iceman"] >> HP["lion"] >> HP["wolf"]; cin >> ATK["dragon"] >> ATK["ninja"] >> ATK["iceman"] >> ATK["lion"] >> ATK["wolf"]; while(game.t <= T && game.t != -1) game.turn(); } return 0; } |
java:
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
import java.util.*; import java.io.*; import java.math.*; import java.util.HashMap; class Weapon{ static int R; int atk; Weapon(int type, int _atk){ if(type == 0)atk = _atk / 5; if(type == 1)atk = 100; if(type == 2)atk = 3; } } class SAM{ int atk; int hp; int id; int loyalty; int step; String color; String type; double morale; Weapon[] wea = new Weapon[3]; static HashMap<String, Integer> HP = new HashMap<String, Integer>(); static HashMap<String, Integer> ATK = new HashMap<String, Integer>(); SAM(String _color, int _id, String _type, int hhp){ color = _color; id = _id; type = _type; step = 0; morale = 0; loyalty = 100; hp = HP.get(type); atk = ATK.get(type); Weapon WA = new Weapon(id % 3, atk); Weapon WB = new Weapon((id + 1) % 3, atk); if(WA.atk == 0)WA = null; if(WB.atk == 0)WB = null; if(type == "dragon"){ wea[id % 3] = WA; morale = (double)hhp / HP.get("dragon"); } if(type == "ninja"){ wea[id % 3] = WA; wea[(id + 1) % 3] = WB; } if(type == "iceman")wea[id % 3] = WA; if(type == "lion")loyalty = hhp; } String S2str(){ return color + " " + type + " " + Integer.toString(id); } String attr(){ return "with " + Integer.toString(hp) + " elements and force " + Integer.toString(atk); } int usesword(boolean con){ Weapon x = wea[0]; if(x == null)return 0; int res = x.atk; if(con){ x.atk = (int)(x.atk * 0.8); if(x.atk == 0)wea[0] = null; } return res; } int getatk(boolean defense){ if(defense)return atk / 2 + usesword(false); else return atk + usesword(false); } } class HEA{ static String[][] Sam_type = { {"iceman", "lion", "wolf", "ninja", "dragon"}, {"lion", "dragon", "ninja", "iceman", "wolf"}, }; int hp; int Stot; int type; int pos; int rew; String color; HEA(){} HEA(String _color, int _hp, int _pos){ color = _color; hp = _hp; pos = _pos; if(color == "red")type = 0; else type = 1; Stot = 0; } void summon(){ String Stype = Sam_type[type][Stot % 5]; if(SAM.HP.get(Stype) <= hp){ hp -= SAM.HP.get(Stype); Stot++; SAM S = new SAM(color, Stot, Stype, hp); Game.C[pos][type] = S; System.out.printf("%03d:00 %s born\n", Game.t / 60, S.S2str()); if((S.type) == "dragon") System.out.printf("Its morale is %.2f\n", S.morale); if((S.type) == "lion") System.out.printf("Its loyalty is %d\n", S.loyalty); } } }; class Game{ static boolean[] arr = new boolean[25]; static int t, M, N, R, K, T; int[] chp = new int[25]; int[] flag = new int[25]; int[] lastwin = new int[25]; int[] win = new int[25]; HEA H[] = new HEA[2]; static SAM[][] C = new SAM[25][2]; int offen(int x){ if(flag[x] != -1)return flag[x]; if(x % 2 == 0)return 1; else return 0; } void reset(int cas){ System.out.printf("Case %d:\n", cas); t = 0; for(int i = 0; i <= N + 1; i++){ C[i][0] = C[i][1] = null; flag[i] = lastwin[i] = -1; chp[i] = 0; } } void escape(){ for(int i = 0; i <= N + 1; i++) for(int j = 0; j < 2; j++) if(C[i][j] != null && C[i][j].loyalty <= 0 && i != H[j ^ 1].pos){ System.out.printf("%03d:05 %s ran away\n", t / 60, C[i][j].S2str()); C[i][j] = null; } } void move(){ boolean end = false; int[] d = {-1, 1}; SAM[][] tmp = new SAM[25][2]; for(int i = 0; i <= N + 1; i++) for(int j = 0; j < 2; j++){ int u = i + d[j]; if(i == H[j ^ 1].pos)tmp[i][j] = C[i][j]; if(u >= 0 && u <= N + 1 && C[u][j] != null){ SAM S = C[u][j]; S.step++; if(S.step % 2 == 0 && S.type == "iceman"){ S.atk += 20; S.hp = Math.max(1, S.hp - 9); } tmp[i][j] = S; if(i == H[j ^ 1].pos){ System.out.printf("%03d:10 %s reached %s headquarter %s\n", t / 60, S.S2str(), H[j ^ 1].color, S.attr()); if(C[i][j] != null){ System.out.printf("%03d:10 %s headquarter was taken\n", t / 60, H[j ^ 1].color); end = true; } } else System.out.printf("%03d:10 %s marched to city %d %s\n", t / 60, S.S2str(), i, S.attr()); } } for(int i = 0; i <= N + 1; i++) for(int j = 0; j < 2; j++) C[i][j] = tmp[i][j]; if(end)t = -1; } void gethp(){ for(int i = 1; i <= N ; i++) for(int j = 0; j < 2; j++) if(C[i][j] != null && C[i][j ^ 1] == null){ H[j].hp += chp[i]; System.out.printf("%03d:30 %s earned %d elements for his headquarter\n", t / 60, C[i][j].S2str(), chp[i]); chp[i] = 0; } } void shoot(){ for(int i = 1; i <= N; i++)arr[i] = false; for(int i = 0; i <= N + 1; i++) for(int j = 0; j < 2; j++){ SAM u = C[i][j], v = null; int p; if(j == 0)p = i + 1; else p = i - 1; if(p >= 0 && p <= N + 1)v = C[p][j ^ 1]; if(u == null || v == null || u.wea[2] == null)continue; v.hp -= R; u.wea[2].atk--; if(u.wea[2].atk == 0)u.wea[2] = null; if(v.hp > 0)System.out.printf("%03d:35 %s shot\n", t / 60, u.S2str()); else{ System.out.printf("%03d:35 %s shot and killed %s\n", t / 60, u.S2str(), v.S2str()); arr[p] = true; } } } void usebomb(){ for(int i = 1; i <= N; i++){ int p = offen(i); SAM u = C[i][p], v = C[i][p ^ 1]; if(u == null || v == null || arr[i] == true)continue; if(v.wea[1] != null && u.getatk(false) >= v.hp){ System.out.printf("%03d:38 %s used a bomb and killed %s\n", t / 60, v.S2str(), u.S2str()); C[i][p] = C[i][p ^ 1] = null; } else if(u.wea[1] != null && u.getatk(false) < v.hp && v.getatk(true) >= u.hp && v.type != "ninja"){ System.out.printf("%03d:38 %s used a bomb and killed %s\n", t / 60, u.S2str(), v.S2str()); C[i][p] = C[i][p ^ 1] = null; } } } void fight(int pos, int p, boolean defense){ SAM u = C[pos][p], v = C[pos][p ^ 1]; int tmp = Math.max(0, v.hp); if(u.hp > 0 && v.hp > 0) if(!defense || u.type != "ninja"){ v.hp -= u.getatk(defense); u.usesword(true); if(defense) System.out.printf("%03d:40 %s fought back against %s in city %d\n", t / 60, u.S2str(), v.S2str(), pos); else System.out.printf("%03d:40 %s attacked %s in city %d %s\n", t / 60, u.S2str(), v.S2str(), pos, u.attr()); } if(v.hp <= 0 && u.hp > 0){ if(!arr[pos]) System.out.printf("%03d:40 %s was killed in city %d\n", t / 60, v.S2str(), pos); win[pos] = p; if(v.type == "lion")u.hp += tmp; if(u.type == "wolf") for(int i = 0; i < 3; i++) if(u.wea[i] == null)u.wea[i] = v.wea[i]; } } void war(){ for(int i = 1; i <= N; i++)win[i] = -1; H[0].rew = H[0].hp / 8; H[1].rew = H[1].hp / 8; for(int i = 1; i <= N; i++) if(C[i][0] != null && C[i][1] != null){ int p = offen(i); fight(i, p, false); fight(i, p ^ 1, true); if(C[i][p].morale > 0.8 && C[i][p].hp > 0) System.out.printf("%03d:40 %s yelled in city %d\n", t / 60, C[i][p].S2str(), i); if(win[i] != -1){ int w = win[i]; System.out.printf("%03d:40 %s earned %d elements for his headquarter\n", t / 60, C[i][w].S2str(), chp[i]); H[w].hp += chp[i]; chp[i] = 0; if(lastwin[i] == w && flag[i] != w){ flag[i] = w; System.out.printf("%03d:40 %s flag raised in city %d\n", t / 60, H[w].color, i); } lastwin[i] = w; } for(int j = 0; j < 2; j++) if(C[i][j].type == "dragon"){ if(j == win[i])C[i][j].morale += 0.2; else C[i][j].morale -= 0.2; } if(C[i][0].hp > 0 && C[i][1].hp > 0){ for(int j = 0; j < 2; j++) if(C[i][j].type == "lion")C[i][j].loyalty -= K; lastwin[i] = -1; } } for(int i = 1; i <= N; i++) for(int j = 0; j < 2; j++) if(C[i][j] != null && C[i][j].hp <= 0)C[i][j] = null; for(int i = N; i > 0 && H[0].rew > 0; i--) if(win[i] == 0){ H[0].hp -= 8; H[0].rew--; C[i][0].hp += 8; } for(int i = 1; i <= N && H[1].rew > 0; i++) if(win[i] == 1){ H[1].hp -= 8; H[1].rew--; C[i][1].hp += 8; } } void print15(SAM S){ System.out.printf("%03d:55 %s has ", t / 60, S.S2str()); if(S.wea[2] != null){ System.out.printf("arrow(%d)", S.wea[2].atk); if(S.wea[1] != null || S.wea[0] != null)System.out.printf(","); else System.out.printf("\n"); } if(S.wea[1] != null){ System.out.printf("bomb"); if(S.wea[0] != null)System.out.printf(","); else System.out.printf("\n"); } if(S.wea[0] != null)System.out.printf("sword(%d)\n", S.wea[0].atk); if(S.wea[0] == null && S.wea[1] == null && S.wea[2] == null)System.out.println("no weapon"); } void turn(){ int M = t % 60; if(M == 0){ H[0].summon(); H[1].summon(); } if(M == 5)escape(); if(M == 10)move(); if(t == -1)return; if(M == 20)for(int i = 1; i <= N; i++)chp[i] += 10; if(M == 30)gethp(); if(M == 35)shoot(); if(M == 38)usebomb(); if(M == 40)war(); if(M == 50) for(int i = 0; i < 2; i++) System.out.printf("%03d:50 %d elements in %s headquarter\n", t / 60, H[i].hp, H[i].color); if(M == 55){ for(int i = 0; i <= N + 1; i++) if(C[i][0] != null)print15(C[i][0]); for(int i = 0; i <= N + 1; i++) if(C[i][1] != null)print15(C[i][1]); } t++; } void run(boolean debug){ Scanner sc = new Scanner(System.in); int tot = sc.nextInt(); for(int cas = 1; cas <= tot; cas++){ M = sc.nextInt(); N = sc.nextInt(); R = sc.nextInt(); K = sc.nextInt(); T = sc.nextInt(); reset(cas); H[0] = new HEA("red", M, 0); H[1] = new HEA("blue", M, N + 1); String tmp[] = {"dragon","ninja","iceman","lion","wolf"}; for(int i = 0; i < 5; i++) SAM.HP.put(tmp[i], sc.nextInt()); for(int i = 0; i < 5; i++) SAM.ATK.put(tmp[i], sc.nextInt()); while(t <= T && t != -1)turn(); } } } public class Main{ public static void main(String[] args){ Game game = new Game(); game.run(true); } } |
Java直接用list和lambda写更好?速度会慢一些