Problem:
Intersection

For given two segments s1 and s2, print "1" if they are intersect, "0" otherwise.

s1 is formed by end points p0 and p1, and
s2 is formed by end points p2 and p3.

Input

The entire input looks like:

q (the number of queries)
1st query
2nd query
...
qth query

Each query consists of integer coordinates of end points of s1 and s2 in the following format:

xp0 yp0 xp1 yp1 xp2 yp2 xp3 yp3

Output

For each query, print "1" or "0".

Constraints

1 ≤ q ≤ 1000

-10000 ≤ xpi, ypi ≤ 10000

p0 ≠ p1 and
p2 ≠ p3.

Sample Input 1

3
0 0 3 0 1 1 2 -1
0 0 3 0 3 1 3 -1
0 0 3 0 3 -2 5 0

Sample Output 1

1
1
0

Solution in C# (judge verdict: Wrong Answer)

#region ZIPPER
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using sc = Scanner;
using Geometry;
using gl = Geometry.GeometryLibrary;
class Program
{
    static void Main(string[] args)
    {
        Solver solver = new Solver();
        solver.Solve();
#if DEBUG
        System.Console.WriteLine("?¶?????????????????????????????????????????????????????????????");
        System.Console.ReadKey();
#endif

    }
}
/// <summary>
/// ?¨??????\????????????????????´???????????????????????????????????????
/// </summary>
public static class Scanner
{
    public static string NextString()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return tmp;
    }
    public static int NextInt()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return int.Parse(tmp);
    }
    public static long NextLong()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return long.Parse(tmp);
    }
    public static double NextDouble()
    {
        string tmp = "";
        while (true)
        {
            int readData;
            string data;
            readData = Console.Read();
            if (readData == -1) //EOF
            {
                break;
            }
            data = char.ConvertFromUtf32(readData);
            if (data == " " || data == "\n")
            {
                break;
            }
            tmp += data;
        }
        return double.Parse(tmp);
    }

    public static string[] NextStrArray()
    {
        return Console.ReadLine().Split(' ');
    }
    public static int[] NextIntArray()
    {

        string[] s = NextStrArray();
        int[] a = new int[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = int.Parse(s[i]);
        }
        return a;
    }
    public static long[] NextLongArray()
    {
        string[] s = NextStrArray();
        long[] a = new long[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = long.Parse(s[i]);
        }
        return a;
    }
    public static double[] NextDoubleArray()
    {
        string[] s = NextStrArray();
        double[] a = new double[s.Length];
        for (int i = 0; i < a.Length; i++)
        {
            a[i] = double.Parse(s[i]);
        }
        return a;
    }
}
#endregion ZIPPER

public class Solver
{
#region IGNORE_ME
    public Solver()
    {
        //???????????¨?????????????????????????????????????????????
    }
#endregion IGNORE_ME

    public void Solve()
    {
        int q = sc.NextInt();
        Point[] p = new Point[4*q];
        for (int i = 0; i < 4*q; i++)
        {
            p[i] = new Point(sc.NextInt(), sc.NextInt());
        }
        for (int i = 0; i < q; i++)
        {
            int s = 4*i;
            if (gl.DoesIntersect(p[s], p[s + 1], p[s + 2], p[s + 3]))
            {
                Console.WriteLine("1");
            }
            else
                Console.WriteLine("0");
        }
#if DEBUG
        Console.WriteLine("");//local check
#endif
    }
}
namespace Geometry
{
    /// <summary>
    /// ??????x,y??§?¨??????¨???(double???)
    /// </summary>
    public struct dPoint
    {
        public double x;
        public double y;
        public dPoint(int x, int y)
        {
            this.x = (double)x; this.y = (double)y;
        }
        public dPoint(double x, double y)
        {
            this.x = x; this.y = y;
        }
        public static dPoint operator +(dPoint p1, dPoint p2)
        {
            return new dPoint(p1.x + p2.x, p1.y + p2.y);
        }
        public static dPoint operator -(dPoint p1, dPoint p2)
        {
            return new dPoint(p1.x - p2.x, p1.y - p2.y);
        }
        public static dPoint operator *(double s, dPoint p)
        {
            return new dPoint(s * p.x, s * p.y);
        }
    }
    /// <summary>
    /// ??????x,y??§?¨??????¨???(int???)
    /// </summary>
    public struct Point
    {
        public int x;
        public int y;
        public Point(int x, int y)
        {
            this.x = x; this.y = y;
        }
        public static Point operator +(Point p1, Point p2)
        {
            return new Point(p1.x + p2.x, p1.y + p2.y);
        }
        public static Point operator -(Point p1, Point p2)
        {
            return new Point(p1.x - p2.x, p1.y - p2.y);
        }
        public static Point operator *(int s, Point p)
        {
            return new Point(s * p.x, s * p.y);
        }
    }

    public static class GeometryLibrary
    {


        /// <summary>
        /// ??????
        /// </summary>
        /// <returns></returns>
        public static double Naiseki(dPoint p1, dPoint p2)
        {
            return p1.x * p2.x + p1.y * p2.y;
        }
        /// <summary>
        /// ??????
        /// </summary>
        /// <returns></returns>
        public static int Naiseki(Point p1, Point p2)
        {
            return p1.x * p2.x + p1.y * p2.y;
        }
        /// <summary>
        /// ??´???p1,p2???????????????p????°???±
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static dPoint Projection(dPoint p1, dPoint p2, dPoint p)
        {
            dPoint a = p2 - p1;
            dPoint b = p - p1;
            double t = Naiseki(a, b) / Naiseki(a, a);
            return t * a + p1 ;
        }
        /// <summary>
        /// ??´???p1p2???????????????p???????°????p1,p2???????????´?????????????§°??????p????§????
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static dPoint Refrection(dPoint p1, dPoint p2, dPoint p)
        {
            return 2 * Projection(p1, p2, p) - p;
        }

        /// <summary>
        /// p1p2??¨p3p4???2??´????????????
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p3"></param>
        /// <param name="p4"></param>
        /// <returns></returns>
        public static bool IsParallel(Point p1, Point p2, Point p3, Point p4)
        {
            Point a = p2 - p1;
            Point b = p4 - p3;
            if (Naiseki(a, b) * Naiseki(a, b) == Naiseki(a, a) * Naiseki(b, b)) return true;
            return false;
        }
        /// <summary>
        ///  p1p2??¨p3p4???2??´???????????´
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p3"></param>
        /// <param name="p4"></param>
        /// <returns></returns>
        public static bool IsVertical(Point p1, Point p2, Point p3, Point p4)
        {
            Point a = p2 - p1;
            Point b = p4 - p3;
            if (Naiseki(a, b) == 0) return true;
            return false;
        }
        /// <summary>
        ///  p1p2??¨p3p4???2????????????????????? ?????????http://www5d.biglobe.ne.jp/~tomoya03/shtml/algorithm/Intersection.htm
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p3"></param>
        /// <param name="p4"></param>
        /// <returns></returns>
        public static bool DoesIntersect(Point p1, Point p2, Point p3, Point p4)
        {
            Point a = p1 - p2;
            Point b = p3 - p1;
            Point c = p4 - p1;
            long tc = a.x * b.y + a.y * (-b.x);
            long td = a.x * c.y + a.y * (-c.x);
            Point d = p3 - p4;
            Point e = p1 - p3;
            Point f = p2 - p3;
            long ta = d.x * e.y + d.y * (-e.x);
            long tb = d.x * f.y + d.y * (-f.x); 
            if (tc * td <= 0 && ta * tb <= 0) return true;
            return false;
        }
    }
}