Given three non-collinear points whose co-ordinates are p(p1, p2), q(q1, q2) and r(r1, r2) in the X-Y plane. Return the number of integral / lattice points strictly inside the triangle formed by these points.Note: - A point in the X-Y plane is said to be an integral / lattice point if both its coordinates are integral.
Question
Given three non-collinear points whose co-ordinates are p(p1, p2), q(q1, q2) and r(r1, r2) in the X-Y plane. Return the number of integral / lattice points strictly inside the triangle formed by these points.Note: - A point in the X-Y plane is said to be an integral / lattice point if both its coordinates are integral.
Solution
To find the number of integral/lattice points strictly inside the triangle formed by three non-collinear points, you can use the formula derived from Pick's Theorem. Pick's Theorem states that the area of a polygon with vertices at lattice points is equal to the number of interior lattice points plus half the number of boundary lattice points minus one.
However, in this case, we only want the number of interior lattice points, not the boundary points. So, we need to modify the formula a bit.
Here are the steps:
-
Calculate the area of the triangle using the given coordinates p(p1, p2), q(q1, q2) and r(r1, r2). You can use the formula for the area of a triangle given three points:
Area = 1/2 * abs[(p1*(q2-r2) + q1*(r2-p2) + r1*(p2-q2))]
-
Count the number of lattice points on the boundary of the triangle. These are the points that lie on the lines between p and q, q and r, and r and p. You can do this by finding the greatest common divisor (gcd) of the differences in the x and y coordinates of each pair of points, and then subtracting 1 (to exclude the points themselves). Do this for all three pairs and add the results together.
-
Subtract the number of boundary points from twice the area of the triangle and then add 1. This will give you the number of interior lattice points:
Interior points = 2*Area - Boundary points + 1
Remember, the result should be an integer, as we are counting the number of points. If it's not, there might be a mistake in the calculations.
Similar Questions
Find the number of points with integral coordinates which lie inside the triangle formed by joining the points (0, 0), (20,0) and (0, 20).
The number of triangles formed by 4 points, when no three points are collinear is:
The Manhattan distance between two points (x1,y1)(𝑥1,𝑦1) and (x2,y2)(𝑥2,𝑦2) is defined as:|x1−x2|+|y1−y2|.|𝑥1−𝑥2|+|𝑦1−𝑦2|.We call a Manhattan triangle three points on the plane, the Manhattan distances between each pair of which are equal.You are given a set of pairwise distinct points and an even integer d𝑑. Your task is to find any Manhattan triangle, composed of three distinct points from the given set, where the Manhattan distance between any pair of vertices is equal to d𝑑.InputEach test consists of multiple test cases. The first line contains one integer t𝑡 (1≤t≤1041≤𝑡≤104) — the number of test cases. The description of the test cases follows.The first line of each test case contains two integers n𝑛 and d𝑑 (3≤n≤2⋅1053≤𝑛≤2⋅105, 2≤d≤4⋅1052≤𝑑≤4⋅105, d𝑑 is even) — the number of points and the required Manhattan distance between the vertices of the triangle.The (i+1)(𝑖+1)-th line of each test case contains two integers xi𝑥𝑖 and yi𝑦𝑖 (−105≤xi,yi≤105−105≤𝑥𝑖,𝑦𝑖≤105) — the coordinates of the i𝑖-th point. It is guaranteed that all points are pairwise distinct.It is guaranteed that the sum of n𝑛 over all test cases does not exceed 2⋅1052⋅105.OutputFor each test case, output three distinct integers i𝑖, j𝑗, and k𝑘 (1≤i,j,k≤n1≤𝑖,𝑗,𝑘≤𝑛) — the indices of the points forming the Manhattan triangle. If there is no solution, output "0 0 00 0 0" (without quotes).If there are multiple solutions, output any of them.ExampleinputCopy66 43 10 00 -25 -33 -52 -25 40 00 -25 -33 -52 -26 63 10 00 -25 -33 -52 -24 43 00 3-3 00 -310 82 1-5 -1-4 -1-5 -30 1-2 5-4 4-4 20 0-4 14 400000100000 100000-100000 100000100000 -100000-100000 -100000outputCopy2 6 14 3 53 5 10 0 06 1 30 0 0NoteIn the first test case:Points A𝐴, B𝐵, and F𝐹 form a Manhattan triangle, the Manhattan distance between each pair of vertices is 44. Points D𝐷, E𝐸, and F𝐹 can also be the answer.In the third test case:Points A𝐴, C𝐶, and E𝐸 form a Manhattan triangle, the Manhattan distance between each pair of vertices is 66.In the fourth test case, there are no two points with a Manhattan distance of 44, and therefore there is no suitable Manhattan triangle.
Find the number of triangles that can be formed by joining the 6 non-collinear points on a plane.
The points P(0, 6), Q(-5, 3) and R( 3,1) are the vertices of a triangle, which is
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.