-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_input.py
More file actions
92 lines (71 loc) · 2.19 KB
/
make_input.py
File metadata and controls
92 lines (71 loc) · 2.19 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
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
import sys
import numpy as np
class point:
def __init__(self, x, y):
self.x = int(x)
self.y = int(y)
def __repr__(self):
return "({},{})".format(self.x, self.y)
def __lt__(self, other):
if self.x == other.x:
return self.y < other.y
return self.x < other.x
def __le__(self, other):
if self.x == other.x:
return self.y <= other.y
return self.x <= other.x
def __gt__(self, other):
if self.x == other.x:
return self.y > other.y
return self.x > other.x
def __ge__(self, other):
if self.x == other.x:
return self.y >= other.y
return self.x >= other.x
def __eq__(self, other):
return self.x == other.x and self.y == other.y
output_file = "input.txt"
f = open(output_file, 'w')
f2 = open("correct.txt", 'w')
size = int(sys.argv[1])
fsize = int(sys.argv[2])
rsize = int(sys.argv[3])
max_value = 1e9
points = []
for i in range(size):
x = np.random.randint(-max_value, max_value)
y = np.random.randint(-max_value, max_value)
points.append(point(x, y))
for p in points:
f.write("INSERT ({},{})\n".format(p.x, p.y))
for _ in range(fsize):
x = np.random.randint(-max_value, max_value)
y = np.random.randint(-max_value, max_value)
p = point(x, y)
f.write("FIND {}\n".format(p))
if (p in points):
f2.write("YES\n")
else:
f2.write("NO\n")
def inside_rect(point, left_bottom, right_top):
return point.x >= left_bottom.x and point.x <= right_top.x and point.y >= left_bottom.y and point.y <= right_top.y
points = sorted(points)
for _ in range(rsize):
x = np.random.randint(-max_value, max_value)
y = np.random.randint(-max_value, max_value)
p1 = point(x, y)
x = np.random.randint(-max_value, max_value)
y = np.random.randint(-max_value, max_value)
p2 = point(x, y)
mn = min(p1, p2)
mx = max(p1, p2)
f.write("RANGE ({},{},{},{})\n".format(mn.x, mn.y, mx.x, mx.y))
insiders = []
for p in points:
if inside_rect(p, mn, mx):
insiders.append(p)
# f2.write(repr(insiders))
f2.write(str(len(insiders)))
f2.write("\n")
f.close()
f2.close()