Problem:


宇宙船 UAZ アドバンス号

 恒星歴 2005.11.5。あなたは宇宙船 UAZ アドバンス号の艦長として敵の宇宙船と交戦しようとしています。 幸い敵の宇宙船はまだこちらに気付かずに静止しています。また、すでに敵の宇宙座標は判明しており強力な直線のビームを放つ「フェザー砲」は発射準備を完了しています。あとは、発射命令を出すばかりです。

ところが、宇宙空間には、敵の設置したエネルギーバリアが存在しています。バリアは三角形をしており「フェザー砲」のビームをはね返してしまいます。また、ビームがバリアに当たれば敵に気付かれて逃げられてしまいます。事前に命中すると判定できなければ、発射命令は出せません。

そこで、UAZ アドバンス号、敵、バリアの位置の宇宙座標(3次元座標 x, y, z) を入力して、ビームがバリアをさけて敵に命中する場合は "HIT"、バリアに当たってしまう場合"MISS"と出力するプログラムを作成してください。

 ただし、バリアはアドバンス号から 3 角形に見えるものだけが対象であり、線分につぶれて見えるものはないものとします。また、バリアは 3 角形の頂点を含む境界でも有効であり、ビームをはね返すものとします。また、敵がバリア内にいる場合は"MISS"と出力して下さい。

x, y, z )を入力して、「フェ
ザー砲」がバリアをさけて敵に命中する場合は“HIT”、バリアに命中してはね返されてしまう場合“MISS”と出力し
て終了するプログラムを作成してください。

 ただし、バリアはアドバンス号から 3 角形に見えるものだけが対象であり、線分につぶれて見えるものはないも
のとします。また、バリアは 3 角形の頂点を含む境界でも有効であり、ビームをはね返すものとします。

-->

Input

入力データの形式は以下のとおりです：

1 行目は、UAZ アドバンス号の座標 (x, y, z) (整数、半角空白区切り)

2 行目は、敵の座標 (x, y, z) (整数、半角空白区切り)

3 行目は、バリアの頂点 1 の座標 (x, y, z) (整数、半角空白区切り)

4 行目は、バリアの頂点 2 の座標 (x, y, z ) (整数、半角空白区切り)

5 行目は、バリアの頂点 3 の座標 (x, y, z ) (整数、半角空白区切り)

Output

HIT または MISS と１行に出力してください。

Constraints

-100 ≤ x, y, z ≤ 100

UAZ アドバンス号と敵が同じ位置にいることはない。

Sample Input 1

-10 0 0
10 0 0
0 10 0
0 10 10
0 0 10

Output for the Sample Input 1

HIT

Sample Input 2

-10 6 6
10 6 6
0 10 0
0 10 10
0 0 10

Output for the Sample Input 2

MISS



Sample input:
-10 0 0
10 0 0
0 10 0
0 10 10
0 0 10


Sample output:
HIT

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)

denom = det(a, b, c)
lower = -0.0000001
upper = 1.0000001

if denom > 0:
    t = det(d, b, c) / denom
    u = det(a, d, c) / denom
    v = det(a, b, d) / denom

    # i am on barrier
    if lower < t < -lower:
        print('HIT')
    elif t > 1:
        print('HIT')
    elif t < lower:
        print('HIT')
    elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
        print('MISS')
    else:
        print('HIT')
else:
    print('HIT')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)

denom = det(a, b, c)
lower = -0.0000001
upper = 1.0000001

if denom > 0:
    t = det(d, b, c) / denom
    u = det(a, d, c) / denom
    v = det(a, b, d) / denom

    # i am on barrier
    if lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
        print('MISS')
    else:
        print('HIT')
else:
    print('HIT')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)

denom = det(a, b, c)
lower = -0.0000001
upper = 1.0000001

if denom > 0:
    t = det(d, b, c) / denom
    u = det(a, d, c) / denom
    v = det(a, b, d) / denom
    
    # i am on barrier
    if t == 0:
        print('HIT')
    elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
        print('MISS')
    else:
        print('HIT')
else:
    print('HIT')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)

denom = det(a, b, c)
EPS = 0.0000001
lower = -EPS
upper = 1 + EPS

if denom > 0:
    t = det(d, b, c) / denom
    u = det(a, d, c) / denom
    v = det(a, b, d) / denom

    # i am on barrier
    if -EPS < t < EPS:
        print('HIT')
    elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
        print('MISS')
    else:
        print('HIT')
else:
    print('HIT')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)

denom = det(a, b, c)
EPS = 0.0000001
lower = -EPS
upper = 1 + EPS

if denom > 0:
    t = det(d, b, c) / denom
    u = det(a, d, c) / denom
    v = det(a, b, d) / denom
    print(t,u,v)

    # i am on barrier
    if -EPS < t < EPS:
        print('HIT')
    elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
        print('MISS')
    else:
        print('HIT')
else:
    print('MISS')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)

denom = det(a, b, c)
EPS = 0.0000001
lower = -EPS
upper = 1 + EPS

if denom > 0:
    t = det(d, b, c) / denom
    u = det(a, d, c) / denom
    v = det(a, b, d) / denom
    print(t,u,v)

    # i am on barrier
    if -EPS < t < EPS:
        print('HIT')
    
    elif t < 0:
        print('HIT')

    # hit barrier
    elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
        print('MISS')

    else:
        print('HIT')
else:
    print('HIT')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)

denom = det(a, b, c)
EPS = 0.0000001
lower = -EPS
upper = 1 + EPS

if denom > 0:
    t = det(d, b, c) / denom
    u = det(a, d, c) / denom
    v = det(a, b, d) / denom
    print(t,u,v)

    # i am on barrier
    if -EPS < t < EPS:
        print('HIT')

    # hit barrier
    elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
        print('MISS')

    else:
        print('HIT')
else:
    print('HIT')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)

denom = det(a, b, c)
EPS = 0.0000001
lower = -EPS
upper = 1 + EPS

if denom > 0:
    t = det(d, b, c) / denom
    u = det(a, d, c) / denom
    v = det(a, b, d) / denom

    # i am on barrier
    if -EPS < t < EPS:
        print('HIT')

    elif t < 0:
        print('HIT')

    # hit barrier
    elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
        print('MISS')

    else:
        print('HIT')
else:
    print('HIT')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)

EPS = 0.0000001
lower = -EPS
upper = 1 + EPS

denom = det(a, b, c)

if denom > lower:
    if denom == 0:
        print('HIT')
        exit()
    
    t = det(d, b, c) / denom
    u = det(a, d, c) / denom
    v = det(a, b, d) / denom

    # i am on barrier
    if -EPS < t < EPS:
        print('HIT')

    # barrier is not between ours
    elif t < 0:
        print('HIT')

    # hit barrier
    elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
        print('MISS')

    else:
        print('HIT')
else:
    print('HIT')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)

EPS = 0.0000001
lower = -EPS
upper = 1 + EPS

denom = det(a, b, c)

if denom > 0:
    t = det(d, b, c) / denom
    u = det(a, d, c) / denom
    v = det(a, b, d) / denom

    if t < -EPS:
        print('HIT')

    # hit barrier
    elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
        print('MISS')

    else:
        print('HIT')
else:
    print('HIT')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math
import random

# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/

def det(a, b, c):
    return + a[0] * b[1] * c[2] \
           + a[2] * b[0] * c[1] \
           + a[1] * b[2] * c[0] \
           - a[2] * b[1] * c[0] \
           - a[1] * b[0] * c[2] \
           - a[0] * b[2] * c[1]

def sub(v0, v1):
    # v0 - v1
    return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])

# me
p0 = list(map(int, input().split()))

# enemy
p1 = list(map(int, input().split()))

# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

def solve(p0, p1, A, B, C):
    a = sub(p1, p0)
    b = sub(A, B)
    c = sub(A, C)
    d = sub(A, p0)

    EPS = 0.0000001
    lower = -EPS
    upper = 1 + EPS

    denom = det(a, b, c)

    if denom > 0:
        t = det(d, b, c) / denom
        u = det(a, d, c) / denom
        v = det(a, b, d) / denom

        if t < lower:
            return 'HIT'

        # hit barrier
        elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
            return 'MISS'

        else:
            return 'HIT'
    else:
        if denom < lower:
            return 'MISS'
        else:
            return 'HIT'

def correct_solve(p0, p1, A, B, C):
    from fractions import Fraction
    def gauss(a):
        if not a or len(a) == 0: return None
        n = len(a)
        for i in range(n):
            if a[i][i] == 0:
                for j in range(i + 1, n):
                    if a[j][i] != 0:
                        for k in range(i, n + 1): a[i][k] += a[j][k]
                        break
                else:
                    return None
            for j in range(n):
                if i != j:
                    r = Fraction(a[j][i], a[i][i])
                    for k in range(i, n + 1): a[j][k] = a[j][k] - a[i][k] * r
        for i in range(n):
            x = Fraction(a[i][i], 1)
            for j in range(len(a[i])):
                a[i][j] /= x
        return a


    uaz = p0
    enemy = [0] + [-x + y for x, y in zip(p1, uaz)]
    b0 = [1] + [x - y for x, y in zip(A, uaz)]
    b1 = [1] + [x - y for x, y in zip(B, uaz)]
    b2 = [1] + [x - y for x, y in zip(C, uaz)]
    sol = gauss(list(map(list, zip(b0, b1, b2, enemy, [1, 0, 0, 0]))))
    if sol and all(0 <= e[-1] <= 1 for e in sol):
        return 'MISS'
    else:
        return 'HIT'

def rand_v():
    return (random.randrange(-100, 100), random.randrange(-100, 100), random.randrange(-100, 100))

if __name__ == '__main__':
    res = solve(p0, p1, A, B, C)
    print(res)


    # while True:
    #     p0 = rand_v()
    #     p1 = rand_v()
    #     A = rand_v()
    #     B = rand_v()
    #     C = rand_v()
    #     result0 = solve(p0, p1, A, B, C)
    #     result1 = correct_solve(p0, p1, A, B, C)
    #
    #     if result0 != result1:
    #         print(p0, p1, A, B, C)
    #     else:
    #         print('same')

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
m = lambda a,b:[a[i]-b[i] for i in range(3)]
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]
def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  n = cross(L2[0],L2[1])
  if dot(ab,n) == 0:
    return 'HIT'
  xa = m(L[0],L[2])
  xb = m(L[1],L[2])
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] for i in range(3)]
  for i in range(1,3):
    if dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) < 0:
      return 'MISS'
  return "HIT"
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
m = lambda a,b:[a[i]-b[i] for i in range(3)]
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]
def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  n = cross(L2[0],L2[1])
  if dot(ab,n) == 0:
    return 'HIT'
  xa = m(L[0],L[2])
  xb = m(L[1],L[2])
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] for i in range(3)]
  for i in range(1,4):
    if dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) < 0:
      return 'MISS'
  return "HIT"
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]

def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  xa = m(L[0],L[2])
  n = cross(L2[0],L2[1])
  if dot(xa,n) != 0:
    return 'HIT'
  if dot(ab,n) == 0:
    return 'HIT'
  xb = m(L[1],L[2])
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] for i in range(3)]
  for i in range(1,4):
    if dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) < 0:
      return 'HIT'
  return "MISS"
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]

def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  xa = m(L[0],L[2])
  xb = m(L[1],L[2])
  n = cross(L2[0],L2[1])
  n = c(1/l(n), n)
  if dot(xa,n) == 0:
    return 'MISS'
  print('point2')
  if dot(ab,n) == 0:
    return 'HIT'
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] + L[2][i] for i in range(3)]
  for i in range(1,4):
    if dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) < 0:
      return 'HIT'
  return "MISS"
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]

def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  xa = m(L[0],L[2])
  xb = m(L[1],L[2])
  n = cross(L2[0],L2[1])
  n = c(1/l(n), n)
  if dot(xa,n) == 0:
    return 'MISS'
  if dot(ab,n) == 0:
    return 'HIT'
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] + L[2][i] for i in range(3)]
  for i in range(1,4):
    if dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) < 0:
      return 'HIT'
  return "MISS"
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]

def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  xa = m(L[0],L[2])
  xb = m(L[1],L[2])
  n = cross(L2[0],L2[1])
  n = c(1/l(n), n)
  if dot(ab,n) == 0:
    return 'HIT'
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] + L[2][i] for i in range(3)]
  for i in range(1,4):
    if dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) < 0:
      return 'HIT'
  return "MISS"
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]

def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  xa = m(L[0],L[2])
  xb = m(L[1],L[2])
  n = cross(L2[0],L2[1])
  n = c(1/l(n), n)
  if abs(dot(xa,n)) < 1e10:
    return 'MISS'
  if abs(dot(ab,n)) < 1e10:
    return 'HIT'
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] + L[2][i] for i in range(3)]
  for i in range(1,4):
    if dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) < 0:
      return 'HIT'
  return "MISS"
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]

def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  xa = m(L[0],L[2])
  xb = m(L[1],L[2])
  n = cross(L2[0],L2[1])
  n = c(1/l(n), n)
  if abs(dot(xa,n)) < 1e-10:
    return 'MISS'
  if abs(dot(ab,n)) < 1e-10:
    return 'HIT'
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] + L[2][i] for i in range(3)]
  for i in range(1,4):
    if dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) < 0:
      return 'HIT'
  return "MISS"
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]

def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  xa = m(L[0],L[2])
  xb = m(L[1],L[2])
  n = cross(L2[0],L2[1])
  n = c(1/l(n), n)
  if abs(dot(ab,n)) < 1e-10:
    return 'HIT'
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] + L[2][i] for i in range(3)]
  for i in range(1,4):
    if dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) < 0:
      return 'HIT'
  return "MISS"
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]

def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  n = cross(L2[0],L2[1])
  n = c(1/l(n), n)
  x = L[2]
  for i in range(3):
    if dot(m(L[0],L[2+i]),n) != 0:
      x = L[2+i]
      break
  xa = m(L[0],x)
  xb = m(L[1],x)
  if dot(ab,n) == 0:
    return 'HIT'
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] + x[i] for i in range(3)]
  for i in range(1,4):
    if dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) < 0:
      return 'HIT'
  return "MISS"
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]
  
def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  n = cross(L2[0],L2[1])
  n = c(1/l(n), n)
  x = None
  for i in range(3):
    if dot(m(L[1],L[2+i]),n) != 0:
      x = L[2+i]
      break
  if not x:
    return 'MISS'
  xa = m(L[0],x)
  xb = m(L[1],x)
  if dot(ab,n) == 0:
    return 'HIT'
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] + x[i] for i in range(3)]
  for i in range(1,4):
    if dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) < 0:
      return 'HIT'
  return "MISS"
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]
  
def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  n = cross(L2[0],L2[1])
  n = c(1/l(n), n)
  x = None
  for i in range(3):
    if dot(m(L[1],L[2+i]),n) != 0:
      x = L[2+i]
      break
  if not x:
    return 'MISS'
  xa = m(L[0],x)
  xb = m(L[1],x)
  if dot(ab,n) == 0:
    return 'HIT'
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] + x[i] for i in range(3)]
  L3 = [dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) for i in range(1,4)]
  if L3[0] > 0 and L3[1] > 0 and L3[2] > 0:
    return 'MISS'
  if L3[0] < 0 and L3[1] < 0 and L3[2] < 0:
    return 'MISS'
  return 'HIT'
print(A())

Submission status: Wrong Answer

Solution code:
dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]
  
def A():
  L=[list(map(int,input().split())) for i in range(5)]
  ab = m(L[1],L[0])
  L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
  n = cross(L2[0],L2[1])
  n = c(1/l(n), n)
  x = L[2]
  xa = m(L[0],x)
  xb = m(L[1],x)
  if dot(xb,n) == 0:
    L3 = [dot(n,cross(L2[i-1],m(L[1],L[2+(i%3)]))) for i in range(1,4)]
    if L3[0] > 0 and L3[1] > 0 and L3[2] > 0:
      return 'MISS'
    if L3[0] < 0 and L3[1] < 0 and L3[2] < 0:
      return 'MISS'
    return 'HIT'
  if dot(ab,n) == 0:
    return 'HIT'
  if dot(n,xa) * dot(n,xb) > 0:
    return 'HIT'
  da = abs(dot(n,xa))/l(n)
  db = abs(dot(n,xb))/l(n)
  a = da / (da + db)
  X = [c((1-a),xa)[i] + c(a,xb)[i] + x[i] for i in range(3)]
  L3 = [dot(n,cross(L2[i-1],m(X,L[2+(i%3)]))) for i in range(1,4)]
  if L3[0] > 0 and L3[1] > 0 and L3[2] > 0:
    return 'MISS'
  if L3[0] < 0 and L3[1] < 0 and L3[2] < 0:
    return 'MISS'
  return 'HIT'
print(A())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
from fractions import Fraction
import sys
if sys.version_info[0]>=3: raw_input=input

def gauss(a):
	if not a or len(a)==0: return None
	n=len(a)
	for i in range(n):
		if a[i][i]==0:
			for j in range(i+1,n):
				if a[j][i]!=0:
					for k in range(i,n+1): a[i][k]+=a[j][k]
					break
			else:
				return None
		for j in range(n):
			if i!=j:
				r = Fraction(a[j][i],a[i][i])
				for k in range(i,n+1): a[j][k] = a[j][k] - a[i][k]*r
	for i in range(n):
		x=Fraction(a[i][i],1)
		for j in range(len(a[i])):
			a[i][j] /= x
	return a

uaz=map(int,raw_input().split())
enemy=[0]+[-x+y for x,y in zip(map(int,raw_input().split()),uaz)]
b0=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)]
b1=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)]
b2=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)]
sol=gauss(list(map(list,zip(b0,b1,b2,enemy,[1,0,0,0]))))
print('MISS' if sol and all(0<=e[-1]<=1 for e in sol) else 'HIT')

Submission status: Accepted

Solution code:
def F(a): return [P[a][i]-P[0][i] for i in [0,1,2]]

def D(X):
  a,b,c,d,e,f,g,h,i=X
  return a*e*i+d*h*c+g*b*f-a*h*f-d*b*i-c*e*g

def G(a):
  X=A[:]; X[a::3]=V;
  return 1.0*D(X)/D0

P=[map(int,raw_input().split()) for _ in [0]*5]
A=[0]*9
V=F(1)
for i in [0,1,2]: A[i::3]=F(i+2)

f=0
D0=D(A)
if D0!=0:
  r1,r2,r3=G(0),G(1),G(2)
  if r1>=0 and r2>=0 and r3>=0 and r1+r2+r3>=1: f=1
print ["HIT","MISS"][f]

Submission status: Accepted

Solution code:
def solve(A, b):
    for i in xrange(3):
        if A[i][i] == 0.0:
            for j in xrange(i+1, 3):
                if A[j][i]!=0.0:
                    A[i], A[j] = A[j], A[i]
                    b[i], b[j] = b[j], b[i]
                    break
        for j in xrange(3):
            if i==j:
                continue
            a = A[j][i] / A[i][i]
            for k in xrange(3):
                A[j][k] -= a * A[i][k]
            b[j] -= a * b[i]
    for i in xrange(3):
        b[i] /= A[i][i]
        A[i][i] = 1.0

u = map(float, raw_input().split())
e = map(float, raw_input().split())
o = map(float, raw_input().split())
p = map(float, raw_input().split())
q = map(float, raw_input().split())

n = [(p[i-2]-o[i-2])*(q[i-1]-o[i-1])-(p[i-1]-o[i-1])*(q[i-2]-o[i-2]) for i in xrange(3)]
v = [e[i]-u[i] for i in xrange(3)]
if sum(n[i]*v[i] for i in xrange(3))==0.0:
    print "HIT"
    exit(0)

A = [[p[i]-o[i], q[i]-o[i], e[i]-u[i]] for i in xrange(3)]
b = [e[i] - o[i] for i in xrange(3)]
solve(A, b)
s, t, x = b
j = lambda x: -0.0000001 < x < 1.0000001
if j(s) and j(t) and j(s+t) and j(x):
    print "MISS"
else:
    print "HIT"