QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639912#9227. Henry the PlumberpropaneRE 25ms11740kbPython31.4kb2024-10-13 23:51:262024-10-13 23:51:26

Judging History

你现在查看的是最新测评结果

  • [2024-10-13 23:51:26]
  • 评测
  • 测评结果:RE
  • 用时:25ms
  • 内存:11740kb
  • [2024-10-13 23:51:26]
  • 提交

answer

from fractions import Fraction
from math import gcd

def dot(a, b):
    return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]    

def minus(a, b):
    return (a[0] - b[0], a[1] - b[1], a[2] - b[2])

def solve(a1, b1, c1, a2, b2, c2):
    if a1 * b2 == a2 * b1: return None, None
    if a1 == 0 or a2 == 0:
        if a2 == 0:
            a1, a2 = a2, a1
            b1, b2 = b2, b1
            c1, c2 = c2, c1
        y = Fraction(c1 / b)
        x = Fraction(c2 - b2 * y, x2)
        return (x, y)
        
    lcm = abs(a1 * a2) // abs(gcd(a1, a2))
    t1 = lcm // a1
    t2 = lcm // a2
    k1 = b2 * t2 - b1 * t1
    k2 = c2 * t2 - c1 * t1
    y = Fraction(k2, k1)
    x = Fraction(c1 - b1 * y, a1)
    return (x, y) 

for _ in range(int(input())):
    x1, y1, z1 = map(int, input().split())
    x2, y2 = map(int, input().split())
    x3, y3, z3 = map(int, input().split())
    x4, y4 = map(int, input().split())

    p1 = (x1, y1, z1)
    p2 = (x2, y2, 0)
    p3 = (x3, y3, z3)
    p4 = (x4, y4, 0)

    if (dot(minus(p3, p1), p2) == 0 and dot(minus(p3, p1), p4) == 0):
        print(2)
        continue

    x, y = solve(x2, y2, x1 * x2 + y1 * y2, x4, y4, x3 * x4 + y3 * y4)
    if x is None and y is None:
        print(4)
        continue

    a = 1
    b = -(z1 + z3)
    c = z1 * z3 + (x - x1) * (x - x3) + (y - y1) * (y - y3)
    if b * b - 4 * a * c >= 0:
        print(3)
    else:
        print(4)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 25ms
memory: 11740kb

input:

2
-1 -1 3
1 1
2 2 3
2 2
5 5 1
3 0
7 6 -2
1 -2

output:

4
3

result:

ok 2 number(s): "4 3"

Test #2:

score: -100
Dangerous Syscalls

input:

100
-13 -5 -7
-19 19
-19 -13 0
-7 15
-20 20 19
-17 18
20 -20 -1
18 -19
-18 15 -14
-19 18
19 -20 6
20 -19
-12 9 1
7 -16
-13 -14 -8
8 -13
-19 16 9
20 -19
19 -18 -11
19 -18
19 20 -8
12 20
-11 -9 18
-19 -18
8 11 -13
12 -18
18 13 8
4 -18
-16 20 17
-19 18
20 -18 -3
20 -19
-17 -20 -5
-18 -19
19 16 15
19 20...

output:

4
4
4
4
4
4
3
4
4
4
3
4
4
3
3
4
3
4
4
4
4
4
4
4
4
4
4
4
4
3
3
4
4
4
4
4
4
4
4
4

result: