結果
| 問題 | No.168 ものさし |
| コンテスト | |
| ユーザー |
kenkoooo
|
| 提出日時 | 2015-03-20 00:22:16 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,366 bytes |
| 記録 | |
| コンパイル時間 | 2,376 ms |
| コンパイル使用メモリ | 86,008 KB |
| 実行使用メモリ | 67,836 KB |
| 最終ジャッジ日時 | 2024-06-28 23:34:52 |
| 合計ジャッジ時間 | 15,809 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | WA * 6 TLE * 3 -- * 10 |
ソースコード
import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;
public class Main {
private static int[] x;
private static int[] y;
private static final int MAX = 1000000000;
public static void main(String[] args) {
int N = nextInt();
x = new int[N];
y = new int[N];
for (int i = 0; i < N; i++) {
x[i] = nextInt();
y[i] = nextInt();
}
int[][] map = new int[N][N];
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
BigDecimal dist = dist(i, j);
BigDecimal bd1 = dist.divide(new BigDecimal(10));
BigDecimal bd5 = bd1.setScale(0, BigDecimal.ROUND_UP);
int bd2 = bd5.multiply(new BigDecimal(10)).intValue();
map[i][j] = (int) bd2;
map[j][i] = (int) bd2;
}
}
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map[i].length; j++) {
System.out.print(map[i][j] + " ");
}
System.out.println();
}
// ワーシャルフロイト
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (map[i][j] == 0) {
map[i][j] = MAX;
}
}
}
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
map[i][j] = Math.min(map[i][j], Math.max(map[i][k], map[k][j]));
}
}
}
// ワーシャルフロイト終わり
System.out.println(map[0][N - 1]);
}
static BigDecimal dist(int i, int j) {
long xl = x[i] - x[j];
long yl = y[i] - y[j];
BigDecimal b1 = new BigDecimal(xl * xl + yl * yl);
return sqrt(b1, 12);
}
static BigDecimal sqrt(BigDecimal a, int scale) {
// とりあえずdoubleのsqrtを求める
BigDecimal x = new BigDecimal(Math.sqrt(a.doubleValue()), MathContext.DECIMAL64);
BigDecimal b2 = new BigDecimal(2);
for (int tempScale = 8; tempScale < scale; tempScale *= 2) {
// x = x - (x * x - a) / (2 * x);
x = x.subtract(x.multiply(x).subtract(a).divide(x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN));
}
return x;
}
static int nextInt() {
int c;
try {
c = System.in.read();
while (c != '-' && (c < '0' || c > '9'))
c = System.in.read();
if (c == '-')
return -nextInt();
int res = 0;
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = System.in.read();
}
return res;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return -1;
}
}
kenkoooo