Results 1 to 3 of 3
 08232008, 08:30 PM #1Member
 Join Date
 May 2008
 Posts
 9
 Rep Power
 0
given number of points(cordinates) , find max points lie on the same line ?
error while given the test case , it finds 1 point while there are only 2 lines , each one has 2 points
x [ 0 ] = 1 , y [ 0 ] = 5
x [ 1 ] = 5 , y [ 1 ] = 1
x [ 2 ] = 1 , y [ 2 ] = 1
x [ 3 ] = 5 , y [ 3 ] = 5Java Code:private static void solve_it(ArrayList<point> arr) { System.out.println(" new test case "); point p = new point(); point pp = new point(); point ppp = new point(); int slope, slope2, x, y, count = 0; int[][] index = new int[arr.size()][arr.size()]; for (int i = 0; i < arr.size(); i++) { count = 0; p = arr.get(i); System.out.println(" x [ " + i + " ] = " + p.x + " , y [ " + i + " ] = " + p.y); for (int j = 0; j < arr.size(); j++) { if (i == j) { break; } pp = arr.get(j); if ((pp.y  p.y) == 0) { slope = 0; } else { slope = (pp.x  p.x) / (pp.y  p.y); } for (int l = 0; l < arr.size(); l++) { if ((l == i)  (l == j)) { break; } ppp = arr.get(l); if ((ppp.y  p.y) == 0) { slope2 = 0; } else { slope2 = (ppp.x  p.x) / (ppp.y  p.y); } if (slope == slope2) { count++; } } index[i][j] = count; } } for (int q = 0; q < index.length; q++) { System.out.println(); for (int w = 0; w < index.length; w++) { System.out.print(" " + index[q][w]); } } arr.clear(); }
 08232008, 10:07 PM #2
If you are getting errors, copy and paste full text here.
What is your algorithm?
I see code but NO COMMENTs on how you are trying to solve the problem.
 08242008, 01:30 AM #3
Similar Threads

Demonstration of drawing points. It draws a sine wave
By Java Tip in forum SWT TipsReplies: 0Last Post: 06282008, 10:25 PM 
To get the points on the perimeter of a Rounded Rectangle
By rashibahal in forum New To JavaReplies: 6Last Post: 06122008, 10:14 AM 
Find nth root of a number
By perito in forum New To JavaReplies: 1Last Post: 03032008, 07:51 AM 
how to know the number of the line
By simon in forum New To JavaReplies: 3Last Post: 08012007, 05:59 PM
Bookmarks