Algorithm(218)
-
[BOJ] 11653번 : 소인수분해
1. problem : https://www.acmicpc.net/problem/11653 2. solution 1 :#include using namespace std;int n; vector prime_factor(int n) { vector ans; for (int i = 2; i * i > n; vector ans = prime_factor(n); for (auto p : ans) cout source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x12/solutions/11653.cpp basic-algo-lecture/0x12/solutions/11653.cpp at master · encrypted..
2024.09.22 -
[BOJ] 1929번 : 소수 구하기
1. problem : https://www.acmicpc.net/problem/1929 2. solution 1 :#include using namespace std;int n, m; vector eratos(int a) { vector primes; vector numbers(1000005, true); numbers[1] = false; for (int i = 2; i * i > n >> m; vector primes = eratos(m); for (auto p : primes) { if (n sieve of Eratosthenes를 이용해 풀었다. 아직 에라토스네스의 체가 이해가 가지는 않지만, 외워서 풀었다. 여기서 vector 을 이용하면, 공간 절약과 cache hit rate..
2024.09.22 -
[BOJ] 1978번 : 소수 찾기
1. problem : https://www.acmicpc.net/problem/1978 2. solution 1 :#include using namespace std;int n; bool isprime(int a) { if (a == 1) return 0; for (int i = 2; i * i > n; int cnt = 0; for (int i = 0; i > x; cnt += isprime(x); } cout 소수를 찾기 위해서는 숫자 a가 있을 때, root(a)까지만 검사를 해보면 된다. 그 이유는 어떤 수 a의 1이 아닌 제일 작은 약수를 x라고 하자. 이때, a를 x로 나눈 값, 즉, (a / x)는 x보다 크거나 같은 값이 된다. 따라서, x
2024.09.22 -
[BOJ] 2156번 : 포도주 시식
1. problem : https://www.acmicpc.net/problem/2156 2. solution 1 :#include using namespace std;int n; int d[10005][3]; int a[10005];int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i > a[i]; d[1][1] = a[1]; for (int i = 2; i source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x10/solutions/2156_1.cpp basic-algo-lecture/0x10/solutions..
2024.09.22 -
[BOJ] 11656번 : 접미사 배열
1. problem : https://www.acmicpc.net/problem/11656 2. solution 1: #include using namespace std;string s; vector prefix; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> s; for (int i = 0; i prefix라는 배열을 만들어, 접미사들을 추가했다. 정렬은 sort()를 이용했고 , 비교연산자는 lambda함수로 작성했다. 3. solution 2 : // Authored by : std-freejia// Co-authored by : -//http://boj.kr/21378a10916b42d19dce4bc7c841a73c#include ..
2024.09.21 -
[BOJ] 14002번 : 가장 긴 증가하는 부분 수열 4
1. problem : https://www.acmicpc.net/problem/14002 2. solution 1: #include using namespace std;const int nums = 1005;int A; int a[nums]; int d[nums]; int pre[nums]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> A; for (int i = 1; i > a[i]; for (int i = 1; i = a[i]) continue; if (d[i] dq; dq.push_front(mx_idx); cout dp를 이용해 풀었다. 따라서, 세 가지 스텝으로 문제를 풀어나갔다. 첫 번째, 테이블을 정의한다. d..
2024.09.21