NYOJ question 68 three-point Sequence

Source: Internet
Author: User

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;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.