-
Notifications
You must be signed in to change notification settings - Fork 0
/
diehard.cpp
66 lines (66 loc) · 1.59 KB
/
diehard.cpp
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
#include<cstdio>
#include<map>
using namespace std;
struct State {
int health;
int armor;
int st;
bool operator==(const State& stt) const {
return health==stt.health && armor == stt.armor && st == stt.st;
}
bool operator<(const State& stt) const {
return health < stt.health;
}
};
int computeTime(State& state, map<State, int>& mp) {
if(state.health <= 0 || state.armor <= 0) {
return -1;
}
if(mp.find(state) != mp.end()) {
return mp[state];
}
// try all the states
State airState = state;
airState.health += 3;
airState.armor += 2;
airState.st = 1;
int maxTime = 0;
if(state.st != 1) {
int s1 = computeTime(airState, mp) + 1;
maxTime = s1>maxTime?s1:maxTime;
}
State waterState = state;
waterState.health -= 5;
waterState.armor -= 10;
waterState.st = 2;
if(state.st != 2) {
int s2 = computeTime(waterState, mp) + 1;
maxTime = s2>maxTime?s2:maxTime;
}
State fireState = state;
fireState.health -= 20;
fireState.armor += 5;
fireState.st = 3;
if(state.st != 3) {
int s3 = computeTime(fireState, mp) + 1;
maxTime = s3>maxTime?s3:maxTime;
}
mp[state] = maxTime;
return maxTime;
}
int main() {
int test;
scanf("%d", &test);
while(test--) {
int h, a;
scanf("%d %d", &h, &a);
map<State, int> mp;
// step into air
State init;
init.health = h;
init.armor = a;
init.st = -1;
int time = computeTime(init, mp);
printf("%d\n", time);
}
}