본문 바로가기
Algorithm

[구현/수학] 백준 11970 Fence Painting - 파이썬(Python)

by jangThang 2023. 2. 24.
반응형

백준 온라인 저지

 

[ Contents ]

     

     

    1. 문제 (링크 참조)

     

    11970번: Fence Painting

    Several seasons of hot summers and cold winters have taken their toll on Farmer John's fence, and he decides it is time to repaint it, along with the help of his favorite cow, Bessie. Unfortunately, while Bessie is actually remarkably proficient at paintin

    www.acmicpc.net

     

     

    2. 문제 풀이

     좌표평면 상에서 그려지는 사각형의 둘레를 찾는 문제라고 생각하면 됩니다.

     

     

    3. 코드

    import sys
    input = sys.stdin.readline
    
    a, b = map(int, input().split())
    c, d = map(int, input().split())
    
    if c >= b or d <= a:
        print(b-a + d-c)
    else:
        print( max(b,d) - min(a,c) )

      겹치지 않는다면, 그대로 간격을 출력하면 됩니다.

     만약 겹쳐진다면, 최대 - 최소로 간격을 구해 출력합니다.

     

    star가 되고나서 Tistory

    반응형

    댓글