# Project Euler #102: Triangle containment

# Project Euler #102: Triangle containment

jshreyas23 + 1 comment Can somebody let me know test case #1 please? thats the only case i am failing at.

FOREVER_MAPLE + 1 comment There is sth wrong in the problem. you should count triangles which (0,0) lines in the sides.

sjeuler + 0 comments Even bayleef is human I believe

kitchent + 0 comments The description of is contradictory to the constraints . This is what stops me from getting the last two test cases right.

Crafter_Artisan + 0 comments A bit of clarification of criteria is in order.

The origin on one of the sides of a triangle should be counted as IN, not out.

There will be no test cases where the origin itself is one of the triangle corners.

Rohit_9083 + 0 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 ?

shail_kr + 0 comments i am using return abs((x1*(y2-y3) + x2*(y3-y1)+ x3*(y1-y2))/2.0); formula to calculate area. when i am executing it in c++ i pass all the test cases, but when i am executing the same thing in java i onli pass test 0 ... Can anyone explain why ? if both program needed i wud give.. :)

rohitsharmacr + 1 comment Why is it failing for Test Case 5 and 6? Does any one has a clue, what I am missing?

shoban_ + 0 comments Take care of

**int**overflow.

navi_I + 1 comment what if point lies on one of the line..will it be considered or not?

zacker_22Asked to answer + 1 comment if point lies on the line it should NOT be considered as it is not inside of triangle

navi_I + 1 comment i think those points are considered in this questions as my solution has passed all test cases

tusharkashyap301 + 1 comment are you sure about it ?

SanjibDhar + 2 comments Out of 6 test case only 2nd one is failing everytime ... how i will know what is the problem in the code ... Can any one help please

jainnu + 0 comments I have used Long Double (in C) , My code is working till Test case 4, and giving wrong answer for Test case 5 and 6 . How to tackle this ?

Sort 21 Discussions, By:

Please Login in order to post a comment