結果

問題 No.764 浮動点
ユーザー 37zigen37zigen
提出日時 2018-12-01 19:56:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 288 ms / 1,500 ms
コード長 3,574 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 75,092 KB
実行使用メモリ 58,632 KB
最終ジャッジ日時 2023-09-09 06:53:42
合計ジャッジ時間 9,913 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
55,752 KB
testcase_01 AC 118 ms
56,116 KB
testcase_02 AC 119 ms
55,744 KB
testcase_03 AC 181 ms
56,880 KB
testcase_04 AC 247 ms
57,136 KB
testcase_05 AC 184 ms
55,932 KB
testcase_06 AC 248 ms
57,244 KB
testcase_07 AC 192 ms
56,356 KB
testcase_08 AC 264 ms
57,228 KB
testcase_09 AC 212 ms
57,328 KB
testcase_10 AC 277 ms
58,632 KB
testcase_11 AC 201 ms
56,552 KB
testcase_12 AC 285 ms
57,468 KB
testcase_13 AC 281 ms
57,632 KB
testcase_14 AC 283 ms
57,348 KB
testcase_15 AC 288 ms
57,312 KB
testcase_16 AC 281 ms
57,472 KB
testcase_17 AC 286 ms
57,316 KB
testcase_18 AC 267 ms
57,388 KB
testcase_19 AC 269 ms
55,688 KB
testcase_20 AC 286 ms
57,200 KB
testcase_21 AC 283 ms
57,848 KB
testcase_22 AC 284 ms
57,848 KB
testcase_23 AC 272 ms
57,612 KB
testcase_24 AC 282 ms
57,488 KB
testcase_25 AC 140 ms
55,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//制約の確認

import java.util.*;
import java.io.*;
import java.math.*;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner();
		int N = sc.nextInt();
		if (!(3 <= N && N <= 1000))
			throw new AssertionError();
		double[] L = new double[N + 2];
		for (int i = 0; i <= N + 1; ++i) {
			L[i] = sc.nextInt();
			if (!(1 <= L[i] && L[i] <= 1000))
				throw new AssertionError();
		}
		double[] Ri1 = new double[N + 2];
		double[] Ro1 = new double[N + 2];
		double[] Ri2 = new double[N + 2];
		double[] Ro2 = new double[N + 2];
		for (int i = 1; i <= N; ++i) {
			Ro1[i] = Ro1[i - 1] + L[i];
		}
		Ri1[1] = Ro1[1];
		for (int i = 2; i <= N; ++i) {
			Ri1[i] = abs(Ri1[i - 1], Ro1[i - 1], L[i]);
		}
		for (int i = N; i >= 1; --i) {
			Ro2[i] = Ro2[i + 1] + L[i + 1];
		}
		Ri2[N] = Ro2[N];
		for (int i = N - 1; i >= 1; --i) {
			Ri2[i] = abs(Ri2[i + 1], Ro2[i + 1], L[i + 1]);
		}
		for (int i = 1; i <= N; ++i) {
			System.out.println(String.format("%.20f", solve(Ro1[i], Ri1[i], Ro2[i], Ri2[i], L[0])));
		}
	}

	double solve(double Ro1, double Ri1, double Ro2, double Ri2, double L) {
		return f(Ro1, Ro2, L) - f(Ro1, Ri2, L) - f(Ri1, Ro2, L) + f(Ri1, Ri2, L);
	}

	double abs(double a, double b, double d) {
		if (a <= d && d <= b)
			return 0;
		return Math.min(Math.abs(d - a), Math.abs(d - b));
	}

	double f(double a, double b, double L) {
		if (L >= a + b)
			return 0;
		if (b >= a + L)
			return a * a * Math.PI;
		if (a >= b + L)
			return b * b * Math.PI;
		double x = 0.5 * L + (a * a - b * b) / (2 * L);
		double y = Math.sqrt(a * a - x * x);
		double ang1 = Math.atan2(y, x);
		double ang2 = Math.atan2(y, L - x);
		if (ang1 < 0)
			ang1 += Math.PI;
		if (ang2 < 0)
			ang2 += Math.PI;
		return g(2 * ang1, a) + g(2 * ang2, b);
	}

	double g(double ang, double r) {
		return 0.5 * r * r * (ang - Math.sin(ang));
	}

	void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

}

class Scanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}
}
0