結果

問題 No.306 さいたま2008
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-11-28 10:19:50
言語 Python2
(2.7.18)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 2,514 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 6,700 KB
実行使用メモリ 6,100 KB
最終ジャッジ日時 2023-10-12 05:05:34
合計ジャッジ時間 2,154 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,044 KB
testcase_01 AC 12 ms
5,916 KB
testcase_02 AC 12 ms
6,000 KB
testcase_03 AC 12 ms
5,948 KB
testcase_04 AC 12 ms
6,036 KB
testcase_05 AC 12 ms
5,964 KB
testcase_06 AC 12 ms
6,040 KB
testcase_07 AC 11 ms
6,028 KB
testcase_08 AC 12 ms
6,004 KB
testcase_09 AC 12 ms
6,100 KB
testcase_10 AC 12 ms
5,988 KB
testcase_11 AC 11 ms
6,040 KB
testcase_12 AC 12 ms
5,900 KB
testcase_13 AC 11 ms
6,032 KB
testcase_14 AC 12 ms
5,988 KB
testcase_15 AC 12 ms
5,936 KB
testcase_16 AC 12 ms
5,916 KB
testcase_17 AC 12 ms
6,072 KB
testcase_18 AC 12 ms
5,948 KB
testcase_19 AC 12 ms
5,932 KB
testcase_20 AC 12 ms
6,036 KB
testcase_21 AC 12 ms
5,988 KB
testcase_22 AC 12 ms
5,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
# -*- coding: utf-8 -*-
# †
from math import sin, cos

eps = 1e-9
equal = lambda a, b: abs(a-b) < eps
greater_than = lambda a, b: a + eps > b
less_than = lambda a, b: a < b + eps

class Complex(object):
    def __init__(self, x, y): self.x, self.y = x, y
    def __add__(self, other): return Complex(self.x + other.x, self.y + other.y)
    def __sub__(self, other): return Complex(self.x - other.x, self.y - other.y)
    def __mul__(self, other):
        if type(other) is Complex:
            return Complex(self.x * other.x - self.y * other.y, self.x * other.y + other.x * self.y)
        else:
            return Complex(self.x * other, self.y * other)
    def __rmul__(self, other): return self * other
    def __div__(self, other):
        if type(other) is Complex:
            rr= other.x**2 + other.y**2
            p = (other.x * self.x + other.y * self.y) / float(rr)
            q = (other.x * self.y - other.y * self.x) / float(rr)
            return Complex(p, q)
        else:
            return Complex(self.x / float(other), self.y / float(other))
    def __eq__(self, other): return equal(self.x, other.x) and equal(self.y, other.y)
    def __ne__(self, other): return not (self == other)
    def __lt__(self, other): return self.x < other.x if self.x != other.x else self.y < other.y
    def __gt__(self, other): return self.x > other.x if self.x != other.x else self.y > other.y
    def norm(self): return self.x**2 + self.y**2
    def __abs__(self): return self.norm() ** .5
    def conjugate(self): return Complex(self.x, -self.y)
    @staticmethod
    def polar(rho, theta): return Complex(rho * cos(theta), rho * sin(theta))
    def __repr__(self):
        if equal(self.y, 0): return '{:.06f}'.format(self.x)
        if equal(self.x, 0): return '{:.06f}i'.format(self.y)
        op = '+' if self.y >= 0 else '-'
        return '{:.06f} {} {:.06f}i'.format(self.x, op, abs(self.y))

Point1 = lambda xy: Complex(*xy)
Point = Complex

def cross(p0, p1): return (p0.conjugate() * p1).y

# (ΦωΦ)<2直線の交点
def crosspoint_ll(a0, a1, b0, b1):
    d0 = cross(b1-b0, b0-a0)
    d1 = cross(b1-b0, a1-a0)
    if equal(d0, 0) and equal(d1, 0): return a0 # 同じ直線
    if equal(d1, 0): raise '(;ω;)<交点がないです'
    return a0 + float(d0)/d1 * (a1-a0)

pa = Point1(map(int, raw_input().split()))
pb = Point1(map(int, raw_input().split()))
pb.x *= -1
sa = Point(0, 0)
sb = Point(0, 1)
res = crosspoint_ll(pa, pb, sa, sb)
print '{:.12f}'.format(res.y)
0