You are viewing a single comment's thread. Return to all comments →
import java.io.*; import java.util.*; import java.math.*; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int count=0; for(int i=0;i<n;i++){ int x1=sc.nextInt(); int y1=sc.nextInt(); int x2=sc.nextInt(); int y2=sc.nextInt(); int x3=sc.nextInt(); int y3=sc.nextInt(); int result= Ans(x1,y1,x2,y2,x3,y3); // System.out.println(result); if(result==1){ count=count+1; } } System.out.println(count); /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ } static int Ans(int x1,int y1,int x2,int y2,int x3,int y3){ // \displaystyle T = \frac{1}{2} | (x_A - x_c)(y_B-y_A) - (x_A - x_B)(y_C-y_A)| // area1 .... 0 0 x2 y2 x3 y3 // area2 ... x1 y1 0 0 x3 y3 // area 3 ... x1 y1 x2 y2 0 0 // area... int area=Math.abs((x1-x3)*(y2-y1)-(x1-x2)*(y3-y1)); int area1=Math.abs((0-x3)*(y2-0)-(0-x2)*(y3-0)); int area2=Math.abs((x1-x3)*(0-y1)-(x1-0)*(y3-y1)); int area3=Math.abs((x1-0)*(y2-y1)-(x1-x2)*(0-y1)); // System.out.println(area+" "+(area1+area2+area3)); if(area==area1+area2+area3){ return 1; } else { return 0; } } }
why is case#5 and case#6 wrong with the above code...can someone help me ?
Project Euler #102: Triangle containment
You are viewing a single comment's thread. Return to all comments →
why is case#5 and case#6 wrong with the above code...can someone help me ?