Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- N,Q = input().split()
- N,Q = int(N),int(Q)
- Np = [0]*N
- for i in range(N):
- Np[i] = input().split()
- for j in range(2):
- Np[i][j] = int(Np[i][j])
- def distance_sqr(a,b):
- return (a[0]-b[0])**2 + (a[1]-b[1])**2
- def d_distance_sqr (a,c):
- return max(distance_sqr(a[0],c), distance_sqr(a[1],c))
- def closest_vector_pair(ar, N):
- d = 2**16
- a = 0
- for i in range(len(ar)):
- if d > d_distance_sqr([ar[i-1],ar[i]], N):
- d = d_distance_sqr([ar[i-1],ar[i]], N)
- a = i
- return [ar[a-1],ar[a]]
- def scalar_prod(a, b):
- return a[0]*b[0] + a[1]*b[1]
- def is_dot_inside(ar, N):
- t = 0
- c = closest_vector_pair(ar, N)
- if c[1][0] - c[0][0] == 0: #dx = 0
- if c[1][1] - c[0][1] > 0: #dy > 0
- if (N[0] - c[1][0]) >= 0:
- t=1
- else:
- t=0
- elif c[1][1] - c[0][1] < 0: #dy < 0
- if (N[0] - c[1][0]) <= 0:
- t=1
- else:
- t=0
- elif c[1][1] - c[0][1] == 0: #dy = 0
- if c[1][0] - c[0][0] > 0: #dx > 0
- if N[1] - c[1][1] <= 0:
- t=1
- else:
- t=0
- elif c[1][0] - c[0][0] < 0: #dx < 0
- if N[1] - c[1][1] >= 0:
- t=1
- else:
- t=0
- return t
- for i in range(Q):
- temp = 0
- M = int(input())
- Mi = [0]*M
- for k in range(M):
- Mi[k] = input().split()
- for j in range(2):
- Mi[k][j] = int(Mi[k][j])
- for j in range(N):
- temp += int(is_dot_inside(Mi, Np[j]))
- print(temp)
Add Comment
Please, Sign In to add comment