MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / main

Method main

src/class138/Other3.java:63–104  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

61 }
62
63 public static void main(String[] args) throws IOException {
64 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
65 StreamTokenizer in = new StreamTokenizer(br);
66 PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
67 in.nextToken();
68 n = (int) in.nval;
69 while (n != 0) {
70 for (int i = 1; i <= n; i++) {
71 in.nextToken();
72 x[i] = (int) in.nval;
73 in.nextToken();
74 y[i] = (int) in.nval;
75 in.nextToken();
76 z[i] = (int) in.nval;
77 }
78 for (int i = 1; i <= n; i++) {
79 for (int j = 1; j <= n; j++) {
80 if (i != j) {
81 dist[i][j] = Math.sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
82 cost[i][j] = Math.abs(z[i] - z[j]);
83 }
84 }
85 }
86 double l = 0, r = 100, x;
87 // 二分进行60次,足够达到题目要求的精度
88 // 二分完成后,l就是答案
89 for (int i = 1; i <= 60; i++) {
90 x = (l + r) / 2;
91 if (prim(x) <= 0) {
92 r = x;
93 } else {
94 l = x;
95 }
96 }
97 out.printf("%.3f\n", l);
98 in.nextToken();
99 n = (int) in.nval;
100 }
101 out.flush();
102 out.close();
103 br.close();
104 }
105
106}

Callers

nothing calls this directly

Calls 4

primMethod · 0.95
sqrtMethod · 0.80
flushMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected