結果
| 問題 |
No.306 さいたま2008
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-28 10:19:50 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 2,514 bytes |
| コンパイル時間 | 124 ms |
| コンパイル使用メモリ | 7,168 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2025-02-14 12:10:52 |
| 合計ジャッジ時間 | 1,406 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#!/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)