ABC144 D - Water Bottle

備忘録

問題

atcoder.jp

回答

import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array
import time
import numpy as np
from numpy import linalg as LA

# 時々使う
# import numpy as np
# from decimal import Decimal, ROUND_HALF_UP
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


# MOD = 10 ** 9 + 7
MOD = 998244353
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b, x = il()
    x /= a

    if a * b == x:  # 満杯の場合
        print(0)
    elif x <= a * b / 2:  # 傾けたとき、水が三角形に収まる場合
        # 三角形の面積から傾けたときのa'の長さを求める
        # a' * b / 2 = x -> a' = 2 * x / b
        aa = 2 * x / b
        # ∠A を求める
        print(math.atan2(b, aa) * (180 / math.pi))
    else:  # 傾けたとき、水が台形になる場合
        # 台形の面積から傾けたときのb'の長さを求める
        # (b' - b) * a / 2 = x => b' = 2 * x / a - b
        bb = 2 * x / a - b
        # ∠A を求める
        print(math.atan2(b-bb, a) * (180 / math.pi))


if __name__ == '__main__':
    main()

AtCoder Beginner Contest 144 D - Water Bottle - Qiita

AtCoder ABC 144 D - Water Bottle (茶色, 400 点) - けんちょんの競プロ精進記録