n = int(input())
locs = [list(map(int, input().split())) for _ in range(n)]
xs, xt = map(int, input().split())
ys, yt = map(int, input().split())
cnt = 0
for x, y in locs:
if (xs <= x <= xt) and (ys <= y <= yt):
cnt += 1
print(cnt)
問題文と入力値を見て気が遠くなった一人です。(´ω`)ノ
平面図にしてみるとこうなります。
locs = [[-9, 5], [0, 4], [2, -6], [7, -4], [-3, -1]]
(xs, ys) = (-5, -5)
(xt, yt) = (5, 5)
|
-9 |
-8 |
-7 |
-6 |
-5 |
-4 |
-3 |
-2 |
-1 |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
-6 |
|
|
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
-5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
-3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-1 |
|
|
|
|
|
|
4 |
|
|
|
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
|
|
|
|
|
|
|
|
1 |
|
|
|
|
|
|
|
5 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
平面上の 0 ~ 4 は locs
の要素番号に対応しています。そして locs
の要素番号 0 から順に、その座標の点が 長方形の内部 に含まれているかを 文で調べていきます。
cnt = 0
for x, y in locs:
if (xs <= x <= xt) and (ys <= y <= yt):
cnt += 1
locs = [[-9, 5], [0, 4], [2, -6], [7, -4], [-3, -1]]
(xs, ys) = (-5, -5)
(xt, yt) = (5, 5)
【要素番号 0】
x: -5 <= -9 <= 5 → False
【要素番号 1】
x: -5 <= 0 <= 5
y: -5 <= 4 <= 5 → True
cnt = 1
【要素番号 2】
x: -5 <= 2 <= 5
y: -5 <= -6 <= 5 → False
【要素番号 3】
x: -5 <= 7 <= 5 → False
【要素番号 4】
x: -5 <= -3 <= 5
y: -5 <= -1 <= 5 → True
cnt = 2 ← 結果
となります。