Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- //the code is small, its the comments that are making it look bigger, the comments are for better understanding
- //using struct for easy passing to functions and easy calculations
- struct point{
- // taking long long, because their multiplication may overload in int
- long long int x,y;
- };
- // To find orientation of ordered triplet (s, e, r).
- // The function returns following values
- // 0 --> s, e and r are collinear
- // 1 --> Clockwise side
- // 2 --> Counterclockwise side
- int cross_product_sign(point s, point e, point r)
- {
- //this formula is for cross product of three points
- long long int val = (e.y - s.y) * (r.x - e.x) -
- (e.x - s.x) * (r.y - e.y);
- // since we are only concerned with the sign, we are not returning the values
- if (val == 0) return 0; // collinear
- //though for this problem, they will never be colinear, but we will need this concept for next problem
- return (val > 0)? 1: 2; // clock or counterclock wise
- }
- int main() {
- int t,n;
- point pig, bird, s, e;
- scanf("%d",&t);
- while(t--){
- scanf("%lld %lld %lld %lld",&s.x,&s.y,&e.x,&e.y);
- scanf("%lld %lld",&pig.x,&pig.y);
- scanf("%lld %lld",&bird.x,&bird.y);
- //you have to pass them in same order for both function calls
- int o1 = cross_product_sign(s,e,pig);
- int o2 = cross_product_sign(s,e,bird);
- if(o1!=o2){
- //there sign is not same
- //so on different side
- printf("Lose\n");
- }
- else{
- printf("Win\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement