Algorithm
-
정점들의 거리 - 1761Algorithm/BOJ 2020. 3. 30. 13:46
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 //1761 - 정점들의 거리 #include #include using namespace std; int N, M; vector adj; int parent[40001][17..
-
알파벳 - 1987Algorithm/BOJ 2020. 3. 29. 16:41
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 //1987 - 알파벳 #include using namespace std; int N, M; char arr[20][20]; bool alph[26]; int xarr[4] = {0, 0, 1, -1}; int yarr[4] = {1, -1, 0, 0}; void init() { cin >> N >> M; string s; for (int i = 0; i > s; for (int j = 0; j
-
N-Queen - 9663Algorithm/BOJ 2020. 3. 29. 16:17
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 //9663 - N-Queen #include using namespace std; int N; bool r[15], c[15], dc[29], ic[29]; int di(int x, int y) { return x - y + N-1; } int ii(int x, int y) { return x+y; } int ch(int x, int y, int n) { if(n == N-1) return 1; if(x == N) return 0; r[x] = c[y] = dc[di(x, y)] = ic[i..
-
캔디 분배 - 3955Algorithm/BOJ 2020. 3. 24. 16:25
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 //3955 - 캔디 분배 #include using namespace std; #define MOD 1000000001 int N, K; pair EEA(int a, int b) { long long old_r, r, temp_r; long long old_s, s, temp_s; long long old_t, t, temp_t; long long q; old..
-
이항 계수 3 - 11401Algorithm/BOJ 2020. 3. 24. 00:21
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 //이항 계수 3 - 11401 #include using namespace std; int N, K; long long ans; const long long MOD = 1000000007; long long revM(int a) { long long old_r, r, temp_r; long long old_s, s, temp_s; long long old_t, t, temp_t; long long q; old_r = a, r = MOD; old_s = 1, s = ..
-
Modular 연산에서 나눗셈Algorithm/etc 2020. 3. 23. 22:14
(a/b) % M 은 (a%M) / (b%M) 으로 바꾸어 표현할 수 없습니다. 대신 a/b를 a*a^-1 로 바꾸게 되면 (a*a^-1) % M = (a%M) * (a^-1 % M) 으로는 표현이 가능합니다.(곱셈에 대해서는 가능하기 때문입니다.) 위의 식을 이용하기 위해선 modular 연산에 대한 곱셈의 역원을 구해야 합니다. 1. M이 소수일때 M이 소수라면 저희는 페르마 소정리를 이용할 수 있습니다. 페르마 소정리 : a^p = p (mod p) a^(p-1) = 1 (mod p) 이고, a^(p-1) 를 a*a^(p-2) 로 나누게 되면 a의 p모듈러 영역에 대한 곱셈의 역원은 a^(p-2) 가 됩니다. 2. M이 소수가 아닐때 그리고 a와 M이 서로소 일때 ★a와 M이 서로소가 아니면 곱셈에..
-
단어 암기 - 18119Algorithm/BOJ 2020. 3. 23. 11:55
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 //18119 - 단어암기 #include using namespace std; int N, M; int count[10000]; int full[10000]; int bucket[10000][26]; void init() { cin >> N >> M; for(int i = 0; i c; if (flag == 1) { for (int j = 0; j 0) { bucket[j][c-'..