본문 바로가기

python-algorithm1422

[백준] 9653 1 2 3 4 5 6 7 8 9 10 11 print(" 8888888888 888 88888") print(" 88 88 88 88 88 88") print(" 8888 88 88 88 88888") print(" 88 88 888888888 88 88") print("88888888 88 88 88 88 888888") print("") print("88 88 88 888 88888 888888") print("88 88 88 88 88 88 88 88") print("88 8888 88 88 88 88888 8888") print(" 888 888 888888888 88 88 88") print(" 88 88 88 88 88 88888888") cs 사실 이런 문제들을 선호하는 편은 아닙니다만.. .. 2021. 3. 3.
[백준] 8370 1 2 a,b,c,d=map(int,input().split()) print(a*b+c*d) cs 2021. 3. 3.
[백준] 6749 1 print(-1*int(input())+int(input())*2) cs 아가들 3명인데 나이가 등차수열이고 막내랑 둘째 나이 주고 첫째는 몇살이냐~ 묻는 문제입니다. 2021. 3. 3.
[백준] 5522 1 2 3 4 n=0 for i in range(5): n+=int(input()) print(n) cs 2021. 3. 3.
[백준] 2914 1 2 a,b=map(int, input().split()) print(a*(b-1)+1) cs 이 문제는 문제 설명이 이해하기 어려워서 추천드리지 않습니다 2021. 3. 3.
[백준] 1417 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import sys n=int(sys.stdin.readline()) dasom=int(sys.stdin.readline()) if n!=1: tmp=[] for i in range(n-1): tmp.append(int(sys.stdin.readline())) tmp=sorted(tmp,reverse=True) chk=0 while tmp[0]>= dasom: dasom+=1 tmp[0]-=1 chk+=1 tmp=sorted(tmp,reverse=True) print(chk) else: print(0) Colored by Color Scripter cs 사실 처음 막 구현할때는 입력받아서 최고 득표자랑 다솜이가 받은 차만 구하면 되겠다.. 2021. 3. 2.
[백준] 4328 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import sys def tmodecimal(tmp, b): ans='' while tmp>=b: ans+=str(tmp%b) tmp//=b ans+=str(tmp) return ans[::-1] while 1: n=input() if n=='0': break b,tmp1,tmp2=n.split() tmp1=int(tmp1,int(b)) tmp2 = int(tmp2, int(b)) print(tmodecimal(tmp1%tmp2,int(b))) cs 2021. 2. 26.
[백준] 4299 1 2 3 4 import sys a,b=map(int, sys.stdin.readline().split()) if (a+b)%2==1 or b>a: print(-1) else: print( (a+b)//2, (a-b)//2 ) cs 일단 이 문제는 사족이 너무 깁니다. 그래서 입력과 출력만 보면되는데 공책에 적어보면서 풀면 이해가 쉬운데요 합과 차를 더하면 반드시 짝수가 나와야 합니다. 그리고 '차'라는 건 큰 값에서 작은 값을 뺀 값이라 반드시 0보다 크거나 같습니다. 그리고 혹시나 '차'가 '합'보다 큰 경우도 입력될수도 있어서 예외 처리했습니다. 2021. 2. 26.
[백준] 3943 1 2 3 4 5 6 7 8 9 10 import sys for _ in range(int(sys.stdin.readline())): tmp=[] n=int(sys.stdin.readline()) while True: if 1 in tmp: break tmp.append(n) if n%2==0 : n//=2 else: n=n*3+1 print(max(tmp)) cs 일단 문제 자체는 쉬운데 문제는 시간제한이 걸려서 pypy3 로 통과했습니다. 손으로 그려가면서 해보니 n이 2의 제곱수가 되면 반복문을 탈출하는 것으로 하면 아마 시간이 조금 더 단축 될 것 같습니다. 2021. 2. 26.
[백준] 2997 1 2 3 4 tmp=sorted(list(map(int,input().split()))) if tmp[1]-tmp[0] == tmp[2] -tmp[1]: print(2*tmp[2]-tmp[1]) elif tmp[2]-tmp[1]> tmp[1]- tmp[0] : print( (2*tmp[2]+tmp[0])//3) else: print( (2*tmp[0]+tmp[2])//3) Colored by Color Scripter cs 등차수열인데 우선 입력되는 숫자 3개가 정렬이 안돼있으므로 정렬부터합니다. line 1 이렇게 되면 경우의 수가 크게 3가지입니다. a b c를 입력받은 숫자라고 가정하고 우리가 출력해야할 숫자가 x 라고하면 case1) a b c x, x a b c case2) a b x c ca.. 2021. 2. 26.
[백준] 2765 1 2 3 4 5 6 7 8 9 10 import sys pi=3.1415927 n=1 while True: a,b,c=map(float, sys.stdin.readline().split()) if b ==0 : break distance=a/(5280*12) *pi*b mph=distance/c *3600 print("Trip #%d: %.2f %.2f" %(n,distance,mph)) n+=1 Colored by Color Scripter cs 사실 크게 어려운 문제는 아닌데 대단히 귀찮습니다 2021. 2. 25.
[백준] 2740 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 x=[] y=[] xa,xb=map(int, input().split()) for i in range(xa): x.append(list(map(int, input().split()))) ya,yb=map(int, input().split()) for i in range(ya): y.append(list(map(int, input().split()))) result=[] for i in range(xa): result.append([0]*yb) for i in range(len(x)): for j in range(len(y[0])): for k in range(len(y)): result[i][j] += x[i][k] * y[k][.. 2021. 2. 23.