pangfengliu / programmingtasks

programming tasks from my courses
67 stars 17 forks source link

Mosaics #328

Open littlehug opened 7 years ago

littlehug commented 7 years ago

Task Description

A 2D space is fully covered by 1*1 mosaic pieces. Given three points p1 = (x1, y1), p2 = (x2, y2), p3 = (x3, y3), calculate the number of mosaic pieces that are fully within the triangle formed by those three points. Note that a mosaic piece is fully within the triangle if its four corners are all located inside the triangle, or on the edge of the triangle.

Take figure 1 for example. Given three points (3, 3), (10, 2) and (8, 8), there are 12 mosaic pieces located inside the triangle, which are colored in blue.

![figure 1]()

Input

The input file contains a single line with 6 integers x1, y1, x2, y2, x3 and y3, representing the three corners of the triangle.

Output

Output the number of mosaic pieces fully located inside the triangle.

Sample Input 1

3 3 10 2 8 8

Sample Output 1

12

Sample Input 2

0 0 10 0 0 10

Sample Output 2

45

Sample Input 3

20 -2 -16 39 11 -27

Sample Output 3

538