DMPG '18 G5 - Triangles

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Given N points with coordinates (x1,y1),(x2,y2),,(xN,yN), determine the largest possible area of a triangle formed by three of these N points.

Constraints

For all subtasks:

|xi|,|yi|10000 for all 1iN.

All coordinates are guaranteed to be distinct.

Subtask 1 [30%]

3N500

Subtask 2 [70%]

3N4000

Input Specification

The first line will contain a single integer, N.
The next N lines will each contain two space separated integers xi and yi, the coordinates of the ith point.

Output Specification

Output a single number, the largest possible area. Your answer will be judged as correct if your area has an absolute error of no more than 103.

Sample Input 1

Copy
7
2 13
5 5
-6 3
0 0
7 10
-8 4
2 3

Sample Output 1

Copy
56.000

Sample Input 2

Copy
3
1 5
4 5
7 5

Sample Output 2

Copy
0.000

Comments


  • 4
    r3mark  commented on Aug. 20, 2018, 5:04 p.m.

    A word of warning to those who use the well-known O(N) rotating callipers solution for this problem: it turns out that this solution is incorrect. I have added a few more test cases to try to hack this solution (although I will not rejudge already accepted solutions). For further details about this, see here.


    • -1
      harry7557558  commented on March 9, 2020, 10:20 a.m.

      I just use three loops for all points on the convex hull and got AC.


      • 3
        Kirito  commented on March 9, 2020, 5:33 p.m.

        The judges were replaced with much faster ones, so it looks like we will need to adjust the time limit.


  • -3
    DarthVader336  commented on April 29, 2018, 7:03 p.m.

    Just use Heron's formula and three loops!


    • 1
      harry7557558  commented on March 9, 2020, 9:11 a.m. edit 4

      You don't have to use Heron's formula. Given three points (x0,y0), (x1,y1), (x2,y2), 12((x1x0)(y2y0)(x2x0)(y1y0)) will give you the area of the triangle defined by these points.


    • 1
      wleung_bvg  commented on April 29, 2018, 7:06 p.m.

      In theory, that should only pass the first subtask. Though the bounds might not be strong enough to prevent that solution from passing...


      • -4
        DarthVader336  commented on April 30, 2018, 4:33 a.m.

        Can you give me a hint on how to pass the second subtask?


      • -2
        DarthVader336  commented on April 30, 2018, 3:39 a.m.

        Good point! I passed the first batch, but I got TLE on the second.