일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- infcon 2024
- 1주일회고
- spring batch 5.0
- 인프콘 2024
- jwttoken
- 커스텀 헤더
- 구글 OAuth login
- 디자인 패턴
- TiL
- 개발자부트캠프추천
- Spring multimodule
- 프로그래머스 이중우선순위큐
- 코딩테스트 준비
- 프로그래머스
- 파이썬
- JavaScript
- 빈 조회 2개 이상
- 전략패턴 #StrategyPattern #디자인패턴
- DesignPattern
- 단기개발자코스
- 빈 충돌
- @FeignClient
- 개발자 취업
- Python
- KPT회고
- 99클럽
- 항해99
- 디자인패턴
- jwt
- 취업리부트코스
- Today
- Total
목록알고리즘 with python/수학 (11)
m1ndy5's coding blog
https://www.acmicpc.net/problem/15650 n, m = map(int, input().split()) pair = [] def comb(start): if len(pair) == m: print(' '.join(str(s) for s in pair)) return for i in range(start, n): pair.append(i+1) comb(i+1) pair.pop() comb(0)연속 3연타 combination문제를 풀었더니 확실해 기억에 남은것 같다.ㅋㅋㅋ 조금 다른 점이 있었다면 0부터가 아니라 1이라서 append할 때 +1을 해준 정도?!이다. 굳!
https://www.acmicpc.net/problem/6603 pair = [] def comb(start, lotto): if len(pair) == 6: print(' '.join(str(s) for s in pair)) return for i in range(start, len(lotto)): pair.append(lotto[i]) comb(i+1, lotto) pair.pop() while True : lotto = list(map(int, input().split())) if lotto[0] == 0: break comb(0, lotto[1:]) print()nCr문제였다! 이전의 Combination 코드에서 개수를 지정하는 len(pair) == 6 일때 return을 해주..
https://www.acmicpc.net/problem/1182 n, s = map(int, input().split()) lst = list(map(int, input().split())) pair = [] cnt = 0 def btracking(start): global cnt if sum(pair) == s and len(pair) > 0: cnt += 1 for i in range(start, n): pair.append(lst[i]) btracking(i + 1) pair.pop() btracking(0) print(cnt) 저번에 풀었던 n과m과 다르게 [1, 3]과 [3, 1]은 똑같다고 보는 중복을 허용하지 않는 combination문제였다. 코드의 차이점은 중복을 허용했던 permuta..
https://www.acmicpc.net/problem/6588 시간초과가 아주 밥먹듯이 난 문제였다. 이거해도 시간초과 저거해도 시간초과~ import sys input = sys.stdin.readline prime = [True for _ in range(1000001)] for i in range(2,1001): if prime[i]: for j in range(2*i, 1000001, i) : if prime[j] : prime[j] = False while(True): n = int(input()) if n==0 : break for i in range(3,1000001,2): if prime[i] and prime[n-i]: print("%d = %d + %d"%(n , i , n-i)) ..
https://www.acmicpc.net/problem/9020 def primes_10000(): prime = [1]*10001 prime[0] = 0 prime[1] = 0 for i in range(2, 101): j = 2 while i*j
https://www.acmicpc.net/problem/2609 a, b = map(int, input().split()) gcd = 1 for i in range(abs(a-b), 1, -1): if a%i == 0 and b%i == 0: gcd *= i a //= i b //= i lcm = gcd*a*b print(gcd) print(lcm)옛날에 학생때 최대공배수 최대공약수를 구할 때 13, 17같은 한번에 알아차리기 어려운 소수들이 있어서 썻던 방법이 큰 수에서 작은 수를 뺀 차이의 약수로 나누는 수를 결정했던 기억이 있었다. 그냥 내가 그렇게 풀었었다ㅋㅋㅋㅋ 근데 그렇게 풀었는데 틀렸다고 나옴ㅎㅎ 근데 정확히 아직 반례를 찾진 못했다ㅜㅜ 그래서 무슨 방법으로 풀어야 잘 풀었다고 소문이 날까..
https://www.acmicpc.net/problem/15649 n, m = map(int, input().split()) pair = [] def btracking(n, m, pair): if len(pair) == m : print(' '.join(map(str,pair))) return for i in range(1, n+1): if i not in pair: pair.append(i) btracking(n, m, pair) pair.pop() btracking(n, m, pair) 굉장히 유명한 문제 중 하나인 n과 m! 하지만 푸는 방법을 모르겠어서 이 문제는 그냥 조금만 고민하다가 구글링 해봤다...ㅎ 알고리즘 중에서 백트래킹 방법을 사용해야했던 문제였다. (스터디에 정리할 예정) [1, ..
https://www.acmicpc.net/problem/4948 import math def cnt_prime_num(n): lst = [1] * ((2*n)+1) lst[0] = 0 lst[1] = 0 for i in range(2, int(math.sqrt(2*n))+1): j = 2 while i*j
https://www.acmicpc.net/problem/1978 import math def is_prime_num(num): if num == 1: return 0 for i in range(2, int(math.sqrt(num))+1): if num % i == 0: return 0 return 1 n = int(input()) lst = list(map(int, input().split())) cnt = 0 for num in lst: if is_prime_num(num) == 1 : cnt += 1 print(cnt)각 수가 소수인지 아닌지 판별하는 문제였다. 소수는 1과 자기자신만을 약수로 갖는 수, 곧 다른 숫자로 나누어 떨어지면 안된다는 뜻이다. 36의 약수를 예시로 들어보자 1 2 3 4..