Skip to content

Instantly share code, notes, and snippets.

@mojaie
Created December 4, 2011 15:24
Show Gist options
  • Save mojaie/1430447 to your computer and use it in GitHub Desktop.
Save mojaie/1430447 to your computer and use it in GitHub Desktop.
AOJ:0012
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while (scn.hasNext()) {
double x1 = scn.nextDouble();
double y1 = scn.nextDouble();
double[] xarr = new double[3];
double[] yarr = new double[3];
xarr[0] = scn.nextDouble() - x1;
yarr[0] = scn.nextDouble() - y1;
xarr[1] = scn.nextDouble() - x1;
yarr[1] = scn.nextDouble() - y1;
xarr[2] = scn.nextDouble() - x1;
yarr[2] = scn.nextDouble() - y1;
double[] sol = simultaneousEquation(xarr, yarr);
if(sol[0] > 0 && sol[1] > 0 && sol[0] + sol[1] < 1) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
public static double[] simultaneousEquation(double[] a, double[] b) {
double[] arr = new double[2];
if (a[0] * b[1] - a[1] * b[0] == 0) {
arr[0] = Double.NaN;
arr[1] = Double.NaN;
} else {
arr[0] = (b[1] * a[2] - a[1] * b[2]) / (a[0] * b[1] - a[1] * b[0]);
arr[1] = (a[0] * b[2] - b[0] * a[2]) / (a[0] * b[1] - a[1] * b[0]);
}
return arr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment