Three-point Sequence
Time Limit: 1000 MS | memory limit: 65535 KB
Difficulty: 3
Description
The coordinates of the three non-collocated vertices A, B, and C must be A triangle. Now let you determine the coordinates of A, B, is C provided clockwise or counterclockwise?
For example:
Figure 1: clockwise
Figure 2: counter-clockwise
<Figure 1> <Figure 2>
Input
Each row is A set of test data, with six integers x1, y1, x2, y2, x3, and y3 representing the horizontal and vertical coordinates of A, B, and C. (The coordinates are between 0 and 10000)
Input 0 0 0 0 0 0 indicates input is complete
Test data cannot exceed 10000 groups
Output
If the three points are clockwise, output 1, and output 0
Sample Input
0 0 1 1 1 3
0 1 1 0 0 0
0 0 0 0 0 0 sample output
0
1. Use the vector cross product to determine whether it is clockwise or clockwise.
If A (x1, y1), B (x2, y2), C (x3, y3) is set, the vectors on both sides of the triangle are:
AB = (x2-x1, y2-y1), AC = (x3-x1, y3-y1)
Then the cross product of AB and AC is: (2*2)
| X2-x1, y2-y1 |
| X3-x1, y3-y1 |
Value: (x2-x1) * (y3-y1)-(y2-y1) * (x3-x1)
Use the right-hand rule to judge:
If ABxAC is greater than 0, the Triangle ABC is counterclockwise;
If ABxAC is <0, the Triangle ABC is clockwise;
If ABxAC = 0, the three points are collocated.
[Cpp]
# Include <stdio. h>
Int main ()
{
Int x1, y1, x2, y2, x3, y3;
While (~ Scanf ("% d", & x1, & y1, & x2, & y2, & x3, & y3) & (x1 + y1 + x2 + y2 + x3 + y3 ))
{
If (x2-x1) * (y3-y1)-(x3-x1) * (y2-y1)> 0)
Printf ("0 \ n"); // counterclockwise
Else
Printf ("1 \ n"); // clockwise
}
Return 0;
}
# Include <stdio. h>
Int main ()
{
Int x1, y1, x2, y2, x3, y3;
While (~ Scanf ("% d", & x1, & y1, & x2, & y2, & x3, & y3) & (x1 + y1 + x2 + y2 + x3 + y3 ))
{
If (x2-x1) * (y3-y1)-(x3-x1) * (y2-y1)> 0)
Printf ("0 \ n"); // counterclockwise
Else
Printf ("1 \ n"); // clockwise
}
Return 0;
}