Time limit: +Ms | Memory Limit:65535KB Difficulty:3
-
-
Describe
-
Now give you the coordinates of the three point a,b,c, they must be able to form a triangle, now let you judge whether A,b,c is given clockwise or counterclockwise?
Such as:
Figure 1: Clockwise given
Figure 2: Counter-clockwise
< figure 1> < figure 2>
-
-
Input
-
-
each row is a set of test data, with 6 integer x1,y1,x2,y2,x3,y3 representing the horizontal ordinate of a,b,c three points, respectively. (Coordinate values from 0 to 10000)
Input 0 0 0 0 0 0 indicates end of input
No more than 10000 test data sets
-
-
Output
-
-
If these three points are given clockwise, output 1, counter-clockwise, output 0
-
-
Sample input
-
-
0 0 1 1 1 30 1 1 0 0 00 0 0 0 0 0
-
-
Sample output
-
-
01
Analysis: From morning water to afternoon ....
The following code is to be compared to the slope.
if (((x2-x1) * (y3-y1)-(y2-y1) * (x3-x1)) >0) cout<<0<<endl;elsecout<<1<<endl;
If the slope of the 1th and 2nd points is greater thanthe slope of the 1th and 3rd points connected straight lines
There is no doubt that this is a counter-clockwise given the 3 points. Conversely, it is clockwise.
#include <iostream> #include <cstring> #include <string>using namespace Std;int main () {int x1,y1,x2, Y2,x3,y3;while (Cin>>x1>>y1>>x2>>y2>>x3>>y3, (x1+y1+x2+y2+x3+y3>0)) {if (( X2-X1) * (y3-y1)-(y2-y1) * (x3-x1)) >0) Cout<<0<<endl;elsecout<<1<<endl;} return 0;}
Nyoj 683-Point order