-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path350c_bombs.py
executable file
·44 lines (36 loc) · 1012 Bytes
/
350c_bombs.py
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
#! /usr/bin/python
import sys
def get_x_dir(x):
if x == 0:
return None
return 'R' if x > 0 else 'L'
def get_y_dir(y):
if y == 0:
return None
return 'U' if y > 0 else 'D'
if __name__ == '__main__':
sys.stdin.readline()
bombs = []
d = 0
for line in sys.stdin.readlines():
x, y = map(int, line.split())
if x == 0 or y == 0:
d += 1
bombs.append((x, y))
bombs.sort(lambda a, b: abs(a[0]) + abs(a[1]) - abs(b[0]) - abs(b[1]))
print len(bombs) * 6 - 2 * d
for b in bombs:
x, y = b
x_dir = get_x_dir(x)
if x_dir != None:
print '1 %d %s' % (abs(x), x_dir)
y_dir = get_y_dir(y)
if y_dir != None:
print '1 %d %s' % (abs(y), y_dir)
print '2'
# go back to (0, 0)
if x_dir != None:
print '1 %d %s' % (abs(x), get_x_dir(-x))
if y_dir != None:
print '1 %d %s' % (abs(y), get_y_dir(-y))
print '3'