본문 바로가기
PS/solved.ac

[CLASS 2]백준 1085번, 4153번, 10250번

by DawIT 2021. 1. 15.
320x100

1085번 : 직사각형에서 탈출

 

처음에 조건을 똑바로 안 읽고 이런 코드를 작성했었다.

 

내 코드(오답):

import math

def pointDistance(x1,y1,x2,y2):
    return math.sqrt((x1-x2)**2 + (y1-y2)**2)

arr = input().split()
x = int(arr[0])
y = int(arr[1])
w = int(arr[2])
h = int(arr[3])
if((0<=x and x<=w)and(0<=y and y<=h)):
    distance = min(abs(w-x),abs(h-y))
elif(0<=x and x<=w):
    distance = min(abs(y-h),abs(y))
elif(0<=y and y<=h):
    distance = min(abs(x-w),abs(x))
else:
    distance = min(pointDistance(x,y,0,0),
    pointDistance(x,y,w,0),
    pointDistance(x,y,0,h),
    pointDistance(x,y,w,h),
    )

print(distance)

 

ㅋㅋㅋㅋ 쉬운문제를 돌아가면서 하는...

 

내 코드:

arr = input().split()
x = int(arr[0])
y = int(arr[1])
w = int(arr[2])
h = int(arr[3])

distance = min(w-x,h-y,x,y)

print(distance)

 

최종적으로 이렇게 제출했다. 아쉬운 점은 파이썬을 너무 오랜만에 해서 map의 존재를 까먹었었던 것이다.

 

x,y,w,h = map(int,input().split())
distance = min(w-x,h-y,x,y)

print(distance)

 

이렇게 작성했으면 더 좋았을 것이다.

 

4153번 : 직각삼각형

 

엄청 간단한 문제이다.

 

내 코드:

while(True):
    arr = list(map(int,input().split()))
    if(arr[0] == 0 and arr[1] == 0 and arr[2] == 0):
        break;
    arr.sort(reverse=True)
    if(arr[0]**2 == arr[1]**2 + arr[2]**2):
        print('right')
    else:
        print('wrong')

 

sort 를 이용하여 큰 수부터 정렬하면 된다.

 

10250번 : ACM 호텔

 

내 코드:

testNum = int(input())
answerList = []
for _ in range(testNum):
    h,w,n = map(int,input().split())
    countH = 0
    countW = 1
    for i in range(n):
        if(countH == h):
            countH = 1
            countW+= 1
            continue

        countH+=1
    
    answerStr = str(countH)
    if(countW < 10):
        answerStr += '0'
    answerStr += str(countW)

    answerList.append(answerStr)

for roomNum in answerList:
    print(roomNum)

 

한글로 된 문제를 이해만 했다면 쉽게 풀 수 있는 문제이다. H진법과 비슷하게 countH를 올리다가 h에 도달하면 countH를 1로 바꾸고 countW를 하나 증가시킨다. 후에 str으로 형변환해서 합쳐주면 된다.

 

ksuk6603 님의 코드:

import sys

n = int(sys.stdin.readline())

for o in range(n):
    h, w, n = map(int, sys.stdin.readline().split())
    n -= 1
    c = (n // h) + 1
    r = ((n % h) + 1) * 100
    print(c + r)

 

진법은 생각했으면서 왜 나머지연산으로 할 생각을 못했을까? 일부러 str으로 형변환 할 필요도 없다...

 

 

solved.ac의 CLASS 2부터 시작한다. 지금은 자료구조같은건 쓸 필요도 없을 정도로 쉽다. 빠르게 진도 나가자!

댓글