Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
why my java solution waAny good test case? import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Poj1118 { private static double getXieLv(int x1, int y1, int x2, int y2) { if (x1 == x2) { return Double.MAX_VALUE; } if (y1 == y2) { return 0; } return (y2 - y1 + 0.0) / (x2 - x1 + 0.0); } /** * @param args */ public static void main(String[] args) { Scanner cin = new Scanner(System.in); while (true) { int n = cin.nextInt(); if (n == 0) { break; } int[] x = new int[n + 1]; int[] y = new int[n + 1]; for (int i = 1; i <= n; i++) { x[i] = cin.nextInt(); y[i] = cin.nextInt(); } if (n == 2) { System.out.println(2); continue; } // sort the points. for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if ((x[i] > x[j]) || (x[i] == x[j] && y[i] > y[j]) ) { int temp = x[i]; x[i] = x[j]; x[j] = temp; temp = y[i]; y[i] = y[j]; y[j] = temp; } } } int max = -1; for (int i = 1; i <= n; i++) { // System.out.println(); Map<Double, Integer> map = new HashMap<Double, Integer>(); for (int j = i+1; j <= n; j++) { double value = getXieLv(x[i], y[i], x[j], y[j]); // System.out.println("value=="+ value); Integer ret = map.get(value); if (ret != null) { max = Math.max(max, ret + 1); map.put(value, ret + 1); } else { map.put(value, 1); } } } System.out.println(max + 1); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator