QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#265834#5106. Islands from the SkyjuampiTL 204ms8580kbPython33.2kb2023-11-25 21:33:072023-11-25 21:33:07

Judging History

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

  • [2023-11-25 21:33:07]
  • 评测
  • 测评结果:TL
  • 用时:204ms
  • 内存:8580kb
  • [2023-11-25 21:33:07]
  • 提交

answer

import math

PI = 2*math.acos(0)

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    
    def __sub__(self, p):
        return Point(self.x - p.x, self.y - p.y)
    
    def __add__(self, p):
        return Point(self.x + p.x, self.y + p.y)
    
    def __mul__(self, c):
        return Point(self.x * c, self.y * c)

    def __truediv__(self, c):
        return Point(self.x / c, self.y / c)

    def len(self):
        return math.hypot(self.x, self.y)


def DotProd(a, b):
    return a.x*b.x + a.y*b.y


def CrossProd(a, b):
    return a.x*b.y - a.y*b.x


def LineSegIntersection(a1, a2, b1, b2):
    cp1 = CrossProd(b2 - b1, a1 - b1)
    cp2 = CrossProd(b2 - b1, a2 - b1)
    if cp1 > 0 and cp2 > 0:
        return False
    if cp1 < 0 and cp2 < 0:
        return False
    cp1 = CrossProd(a2 - a1, b1 - a1)
    cp2 = CrossProd(a2 - a1, b2 - a1)
    if cp1 > 0 and cp2 > 0:
        return False
    if cp1 < 0 and cp2 < 0:
        return False
    return True


while True:
    try:
        N, M = map(int, input().split())
        I = []
        for _ in range(N):
            NI = int(input())
            island = []
            for _ in range(NI):
                x, y = map(float, input().split())
                island.append(Point(x, y))
            I.append(island)
        F1 = []
        F2 = []
        FZ1 = []
        FZ2 = []
        for _ in range(M):
            x1, y1, z1, x2, y2, z2 = map(float, input().split())
            F1.append(Point(x1, y1))
            FZ1.append(z1)
            F2.append(Point(x2, y2))
            FZ2.append(z2)

        lo = 0.0
        hi = PI/2
        for rep in range(64):
            th = (hi + lo) / 2
            seen = [False] * N
            for f in range(M):
                poly = []
                ortho = Point(F1[f].y - F2[f].y, F2[f].x - F1[f].x)
                ortho = ortho / ortho.len()
                poly.append(F1[f] - ortho * (FZ1[f] * math.tan(th)))
                poly.append(F2[f] - ortho * (FZ2[f] * math.tan(th)))
                poly.append(F2[f] + ortho * (FZ2[f] * math.tan(th)))
                poly.append(F1[f] + ortho * (FZ1[f] * math.tan(th)))
                mxx = 1e7
                for point in poly:
                    mxx = max(mxx, point.x)
                for i in range(len(I)):
                    if not seen[i]:
                        fail = False
                        for p in I[i]:
                            cnt = 0
                            for j in range(len(poly)):
                                a = poly[j]
                                b = poly[(j + 1) % len(poly)]
                                cnt += LineSegIntersection(a, b, p, Point(mxx + 1337, p.y + 7331))
                            if cnt % 2 == 0:
                                fail = True
                                break
                        if not fail:
                            seen[i] = True
            if seen == [True] * N:
                hi = th
            else:
                lo = th

        if hi == PI/2:
            print("impossible")
        else:
            print(round((hi + lo) / 2 * 180 / PI, 9))

    except EOFError:
        break

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 8348kb

input:

1 1
3
-5 0
5 0
0 5
-10 10 10 10 10 10

output:

45.0

result:

ok 

Test #2:

score: 0
Accepted
time: 8ms
memory: 8468kb

input:

1 1
3
-5 0
5 0
0 5
-10 0 10 10 0 10

output:

26.565051177

result:

ok 

Test #3:

score: 0
Accepted
time: 4ms
memory: 8284kb

input:

1 1
3
-5 0
5 0
0 5
0 10 10 10 0 10

output:

46.686143342

result:

ok 

Test #4:

score: 0
Accepted
time: 11ms
memory: 8276kb

input:

1 1
3
-5 0
5 0
0 5
0 10 5 10 0 10

output:

59.491041134

result:

ok 

Test #5:

score: 0
Accepted
time: 8ms
memory: 8260kb

input:

1 1
3
-5 0
5 0
0 5
0 10 20 -10 0 10

output:

31.219698447

result:

ok 

Test #6:

score: 0
Accepted
time: 13ms
memory: 8472kb

input:

1 3
3
-5 0
5 0
0 5
-10 0 25 10 0 20
-5 10 10 10 -5 20
-4 1 100 5 10 100

output:

12.528807709

result:

ok 

Test #7:

score: 0
Accepted
time: 6ms
memory: 8448kb

input:

1 2
4
0 0
20 0
20 40
0 40
-10 30 30 30 30 30
-10 10 30 30 10 30

output:

45.0

result:

ok 

Test #8:

score: 0
Accepted
time: 15ms
memory: 8468kb

input:

1 4
4
0 0
20 0
20 40
0 40
-10 30 30 30 30 30
-10 20 30 30 20 30
-10 10 30 30 10 30
10 -10 30 10 50 30

output:

18.434948823

result:

ok 

Test #9:

score: 0
Accepted
time: 22ms
memory: 8392kb

input:

1 2
4
0 0
40 0
40 40
0 40
10 10 10 20 20 20
30 10 10 10 30 20

output:

impossible

result:

ok 

Test #10:

score: 0
Accepted
time: 29ms
memory: 8440kb

input:

1 3
4
0 0
20 0
20 40
0 40
-10 30 30 15 30 30
5 30 30 30 30 30
1 50 30 21 50 30

output:

impossible

result:

ok 

Test #11:

score: 0
Accepted
time: 9ms
memory: 8500kb

input:

1 1
4
0 0
40 0
40 40
0 40
-100 -100 20 100 100 10

output:

63.665752153

result:

ok 

Test #12:

score: 0
Accepted
time: 12ms
memory: 8360kb

input:

1 4
4
-10 -10
10 -10
10 10
-10 10
-100 0 10 100 0 10
0 100 10 0 -100 10
50 50 15 -50 -50 15
-50 50 15 50 -50 15

output:

43.313856658

result:

ok 

Test #13:

score: 0
Accepted
time: 204ms
memory: 8580kb

input:

1 100
100
822286 0
856789 53904
986567 124632
629039 119995
732157 187986
691605 224716
728650 288493
591087 278144
801573 440668
425257 269876
614456 446428
424157 350893
645680 606334
406524 432904
545628 659551
359831 495265
367048 578376
251435 457360
319990 680014
336526 849968
214009 658652
23...

output:

53.790638431

result:

ok 

Test #14:

score: -100
Time Limit Exceeded

input:

100 1
100
461002 481444
460618 481480
460584 481512
460833 481595
460670 481605
460545 481607
460942 481801
460526 481672
460912 481923
460765 481903
460505 481781
460430 481766
460589 481959
460593 482032
460477 481972
460440 481994
460510 482183
460285 481888
460387 482179
460246 481963
460303 482...

output:


result: