-
Notifications
You must be signed in to change notification settings - Fork 13
/
shadows-of-the-knight-episode-1.cpp
120 lines (101 loc) · 2.74 KB
/
shadows-of-the-knight-episode-1.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
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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
// OK
void m_U(int& p_y,
int& p_min_y,
int& p_max_y)
{
int tmp_y;
p_max_y = p_y < p_max_y ? p_y-1: p_max_y;
tmp_y = p_max_y - (p_max_y - p_min_y)/2;
p_y = (tmp_y == p_y) ? tmp_y -1 : tmp_y;
}
// OK
void m_D(int& p_y,
int& p_min_y,
int& p_max_y)
{
int tmp_y;
p_min_y = p_y > p_min_y ? p_y+1: p_min_y;
tmp_y = p_min_y + (p_max_y - p_min_y)/2;
p_y = (tmp_y == p_y) ? tmp_y +1 : tmp_y;
}
// OK
void m_R(int& p_x,
int& p_min_x,
int& p_max_x)
{
int tmp_x;
p_min_x = p_x > p_min_x ? p_x+1 : p_min_x;
tmp_x = p_min_x + (p_max_x - p_min_x)/2;
p_x = (tmp_x == p_x) ? tmp_x +1 : tmp_x;
}
//
void m_L(int& p_x,
int& p_min_x,
int& p_max_x)
{
int tmp_x;
p_max_x = p_x < p_max_x ? p_x-1 : p_max_x;
tmp_x = p_max_x - (p_max_x - p_min_x)/2;
p_x = (tmp_x == p_x) ? tmp_x -1 : tmp_x;
}
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
int main()
{
int W, H; // Dimensions of the building.
cin >> W >> H; cin.ignore();
int N; // maximum number of turns before game over.
cin >> N; cin.ignore();
int X0, Y0; // Initial position
int tmp_x, tmp_y; // temporaries
int min_x(0), max_x(W-1), min_y(0), max_y(H-1); // possible boundaries
cin >> X0 >> Y0; cin.ignore();
while (1) {
string bombDir;
cin >> bombDir; cin.ignore();
if(bombDir == "U")
{
m_U(Y0, min_y, max_y);
}
else if(bombDir == "UR")
{
m_U(Y0, min_y, max_y);
m_R(X0, min_x, max_x);
}
else if(bombDir == "R")
{
m_R(X0, min_x, max_x);
}
else if(bombDir == "DR")
{
m_D(Y0, min_y, max_y);
m_R(X0, min_x, max_x);
}
else if(bombDir == "D")
{
m_D(Y0, min_y, max_y);
}
else if(bombDir == "DL")
{
m_D(Y0, min_y, max_y);
m_L(X0, min_x, max_x);
}
else if(bombDir == "L")
{
m_L(X0, min_x, max_x);
}
else if(bombDir == "UL")
{
m_U(Y0, min_y, max_y);
m_L(X0, min_x, max_x);
}
cout << X0 << " " << Y0 << endl;
}
}