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 |
结果出来了,问题是居然多空一行,想了很久,不知道怎么办了import java.io.File; import java.io.FileNotFoundException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { public static DecimalFormat df = new DecimalFormat("0.00"); public static ArrayList getLength(int x1, int y1, int x2, int y2, int r) { ArrayList lr = new ArrayList(); double sin0 = 0; double cos0 = 0; double d = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); try { sin0 = (x1 - x2) / d; } catch (ArithmeticException e) { sin0 = 0; } double sin1 = r / d; try { cos0 = (y1 - y2) / d; } catch (ArithmeticException e) { cos0 = 1; } double cos1 = Math.sqrt(1 - (r * r / (d * d))); lr.add(x1 - (y1 * ((sin0 * cos1 + sin1 * cos0) / (cos0 * cos1 - sin0 * sin1)))); lr.add(x1 - (y1 * ((sin0 * cos1 - sin1 * cos0) / (cos0 * cos1 + sin0 * sin1)))); return lr; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { ArrayList containers = new ArrayList(); String s = sc.nextLine(); String[] d = s.split(" "); ArrayList al = new ArrayList(); if (Integer.parseInt(d[0]) != 0) { for (int i = 0; i <= Integer.parseInt(d[0]); i++) { al.add(sc.nextLine()); } for (int i = 1; i <= Integer.parseInt(d[0]); i++) { containers .add(getLength( Integer.parseInt(al.get(0).toString() .split(" ")[0]), Integer.parseInt(al.get(0).toString() .split(" ")[1]), Integer.parseInt(al.get(i).toString() .split(" ")[0]), Integer.parseInt(al.get(i).toString() .split(" ")[1]), Integer.parseInt(al.get(i).toString() .split(" ")[2]))); } double[] container1 = new double[2 * containers.size()]; ArrayList container2 = new ArrayList(); int k = 0; for (int i = 0; i < containers.size(); i++) { container1[k] = (Double) (((ArrayList) containers.get(i)) .get(0)); container1[k + 1] = (Double) (((ArrayList) containers.get(i)) .get(1)); k += 2; } for (int i = 0; i<containers.size(); i++) { container2.add((Double)((ArrayList) containers.get(i)).get(1)); } Arrays.sort(container1); int I = -1; while (I < container1.length - 1) { I = I + 1; System.out.print(df.format(container1[I]) + " "); if (container2.contains(container1[I + 1])) { I = I + 1; System.out.println(df.format(container1[I])); } else { I = I + 1; do { I = I + 2; } while (!container2.contains(container1[I])); System.out.println(df.format(container1[I])); } } System.out.println(); } else if (Integer.parseInt(d[0]) == 0) { break; } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator