-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
66 lines (55 loc) · 1.94 KB
/
Main.java
File metadata and controls
66 lines (55 loc) · 1.94 KB
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
package com.jd;
import java.io.BufferedInputStream;
import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
int tankNum = in.nextInt();
int b = in.nextInt(); // 单个碉堡的生命值
int destroy = in.nextInt(); // 单个碉堡的伤害
int d = in.nextInt();
int result = 0;
HashMap<Integer, Integer> diaobao = new HashMap<>();
for (int i = 1; i <= d; i++) {
diaobao.put(i, b); // 将碉堡和生命值放入map
}
while (tankNum >= 0 && diaobao.size() != 0) {
result++;
// 回合1, 坦克进攻
int tempTanke = tankNum;
while (tempTanke >= b && !diaobao.isEmpty()) {
diaobao.remove(diaobao.size() - 1);
tempTanke -= b;
}
if (diaobao.isEmpty()) break;
int curTankeCount = 0;
for (Integer has : diaobao.keySet()) {
curTankeCount += diaobao.get(has);
}
if (tempTanke <= curTankeCount && !diaobao.isEmpty()) {
int temp = curTankeCount - tempTanke;
if (temp <= 0) {
for (Integer key : diaobao.keySet()) {
diaobao.remove(key);
}
} else {
for (Integer key : diaobao.keySet()) {
diaobao.put(key, temp);
}
}
}
// 回合2, 碉堡进攻
if (!diaobao.isEmpty()) {
int curDiaoBao = diaobao.size();
tankNum -= destroy * curDiaoBao;
}
}
if (tankNum >= 0) {
System.out.println(result);
}
if (tankNum < 0 && !diaobao.isEmpty()) {
System.out.println(-1);
}
}
}