QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#639929#9227. Henry the PlumberpropaneWA 25ms11744kbPython31.9kb2024-10-14 00:02:312024-10-14 00:02:31

Judging History

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

  • [2024-10-14 00:02:31]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:11744kb
  • [2024-10-14 00:02:31]
  • 提交

answer

from fractions import Fraction
from math import gcd, sqrt

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 == 0 or a2 == 0:
        if a2 == 0:
            a1, a2 = a2, a1
            b1, b2 = b2, b1
            c1, c2 = c2, c1
        y = Fraction(c1, b1)
        x = Fraction(c2 - b2 * y, a2)
        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())):
    try:
        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:
            z = (-b + sqrt(b * b - 4 * a * c)) / (2 * a)
            if x1 == x and y1 == y and abs(z - z1) < 1e-10:
                print(4)
            elif x3 == x and y3 == y and abs(z - z3) < 1e-10:
                print(4)
            else:
                print(3)
        else:
            print(4)
    except:
        print(x1, y1, z1)
        print(x2, y2)
        print(x3, y3, z3)
        print(x4, y4)
        exit(0)

詳細信息

Test #1:

score: 0
Wrong Answer
time: 25ms
memory: 11744kb

input:

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

output:

-1 -1 3
1 1
2 2 3
2 2

result:

wrong answer 1st numbers differ - expected: '4', found: '-1'