본문 바로가기
728x90

알고리즘322

[python] 파이썬에서 제곱사용할 시 pow(), math.pow(), ** type 차이 파이썬을 사용할 때 제곱을 표현하는 방법은 여러가지가 있다. math.pow(2,3)pow(2,3)2**3 정수형 숫자의 거듭제곱에서 math.pow만 float 형태로 출력# pow 사용print(pow(2,3)) # 8# math.pow 사용import mathprint(math.pow(2,3)) # 8.0# ** 사용print(2**3) # 8 Float 숫자의 거듭제곱에서 모 float 형태로 출력# pow 사용print(pow(2.0,3)) # 8.0 # Time: 2.384185791015625e-05import math# math.pow 사용print(math.pow(2.0,3)) # 8.0 # Time: 1.049041748046875e-05# ** 사용print((2.0)**3) # 8... 2025. 3. 17.
[python] 2차원 리스트 원소 여러개 수정 주사위 움직임으로 배열 변경 될 때 알고리즘 짜기주사위가 회전하여 숫자의 위치가 변할 때 리스트의 여러 원소를 변화 시켜야한다.이 때 리스트 원소를 수정할 때 편한 방법을 정리한다.# 주사위 아래에서 봤을 때 숫자들 (맨 위에 숫자를 제외) -> 즉 6이 주사위 아래 숫자일 때 이야기dice = [[0,5,0],[4,6,3],[0,2,0]]def cur_eyes(): return dice[1][1]def move(d): if d == 'L': dice[1] = [7-cur_eyes(), dice[1][0], dice[1][1]] elif d == 'R': dice[1] = [dice[1][1], dice[1][2], 7-cur_eyes()] elif d ==.. 2025. 3. 16.
[python] 백준 2641 다각형그리기 https://www.acmicpc.net/problem/2641 문제 해결같다고 판정되는 다각형은 오직 시작점의 차이와 역방향 이동 두개의 차이만 허락된다. CODEimport sysinput = sys.stdin.readlinefrom collections import dequeconvert = lambda x: (x+2)%4 if x!=2 else 4n = int(input())sample = deque(map(int, input().split()))rev_sample = deque(map(convert, sample))rev_sample.reverse()cnt = 0result = list()for _ in range(int(input())): x = deque(map(int,input().sp.. 2025. 1. 27.
[python] 백준 2352 반도체 설계 문제 해결가장 길게 오름차순 수열을 만들수 있는 LIS (Longest Increasing Subsequence) 문제원소 하나씩 살펴보면서 가장 최근 이은 값도가 크면 하나 더해주고 작은 값이 나오면 이분탐색 통해 이전 값들에서 하나에 예약 연결한다 생각하고 value값을 바꿔놔도 문제 없다CODEimport sysinput = sys.stdin.readlinefrom bisect import bisect_leftif __name__ == "__main__": n = int(input()) A = list(map(int, input().split())) link = [] for d in A: if not link or link[-1] 2024. 8. 15.
728x90