사용자 도구

사이트 도구


ps:problems:boj:18298

Icebergs

ps
링크acmicpc.net/…
출처BOJ
문제 번호18298
문제명Icebergs
레벨골드 5
분류

기하학

시간복잡도O(N*P)
인풋사이즈N<=1000, P<=50
사용한 언어Python 3.11
제출기록31256KB / 96ms
최고기록96ms
해결날짜2023/04/12

풀이

  • 각 빙산의 넓이를 각각 구해서 더하기만 하면 된다. 각 빙산은 다각형이므로 다각형의 넓이를 구하는 공식을 쓰면 된다.
  • 빙산 한개의 넓이를 구하는데에 O(P)이므로 빙산 N개의 넓이를 구하는데에는 O(NP)가 걸린다.

코드

"""Solution code for "BOJ 18298. Icebergs".

- Problem link: https://www.acmicpc.net/problem/18298
- Solution link: http://www.teferi.net/ps/problems/boj/18298

Tags: [geometry]
"""

import sys
from teflib import geometry


def main():
    N = int(sys.stdin.readline())
    twice_of_area = 0
    for _ in range(N):
        P = int(sys.stdin.readline())
        points = [
            [int(x) for x in sys.stdin.readline().split()] for _ in range(P)
        ]
        twice_of_area += geometry.twice_of_polygon_area(points)

    print(twice_of_area // 2)


if __name__ == '__main__':
    main()

토론

댓글을 입력하세요:
W M O R A
 
ps/problems/boj/18298.txt · 마지막으로 수정됨: 2023/04/12 14:28 저자 teferi