click below for solution

Wednesday, 9 February 2022

Points and Lines Solution|Codesheff starter 25


Given N points of the form (xi,yi) on a 2-D plane.

From each point, you draw 2 lines one horizontal and one vertical. Now some of the lines may overlap each other, therefore you are required to print the number of distinct lines you can see on the plane.

Note:

  • Two horizontal lines are distinct if they pass through different y coordinates.
  • Two vertical lines are distinct if they pass through different x coordinates.

Input Format

  • First line will contain T, number of testcases. Then the testcases follow.
  • Each testcase contains a single integer N, the number of points.
  • The next N lines contain two space separated integers xi,yi, the coordinate of the ith point.

Output Format

For each testcase, output in a single line the number of distinct lines that can be seen on the plane.

Constraints

  • 1T1000
  • 1N105
  • 0Xi,Yi109
  • Sum of N over all test cases is atmost 105.

Sample Input 1 

3
4
1 1
1 0
0 1
0 0
5
0 0
0 1
0 2
0 3
0 4
1
10 10

Sample Output 1 

4
6
2

Explanation

Test Case 1: There are 2 horizontal lines passing through Y=0 and Y=1, and 2 vertical lines passing through X=0 and X=1.

Solution:

click here for solution

No comments:

Post a Comment