> >
본문 바로가기

Algorithm

(31)
[BOJ] 14890번 경사로 Sol1) 재귀#include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;const int MAXN = 105;int n, l, res;int a[MAXN][MAXN], b[MAXN][MAXN];void solved(int arr[MAXN][MAXN], int i, int j, int cnt){ if (j == n) { res++; return; } int cur = arr[i][j]; int next = arr[i][j + 1]; if (cur == next) solved(arr, i, j + 1, cnt + 1); else i..
[BOJ] 14499번 주사위 굴리기 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;const int MAXN = 25;int n, m, x, y, k, dir;int arr[MAXN][MAXN], state[6];int dx[] = {0, 0, -1, 1}; // 동서북남 순서int dy[] = {1, -1, 0, 0};bool out_boundary(){ int nx = x + dx[dir]; int ny = y + dy[dir]; return !(nx >= 0 && nx = 0 && ny 0; i--) state[i] = state[i - 1]; state[0] = tm..
2024 SCPC 예선 1차 합격 후기 대회가 평일 부터 주말 사이에 열려서 일과시간 끝나고 잠깐 짬내서 3문제 풀고 나머지는 실력 부족으로 긁기만 하고 도망갔습니다. 1차도 제대로 못 푸는데 2차는 당연히 떨어질 것 같지만 전역하고 제대로 해보기 위해서 참가에 의의를 두고자 합니다! A. A보다 B가 좋아#include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;int main(){ FASTIO; int t; cin >> t; for (int k = 1; k > n; string s; cin >> s; vector v; for (int i = 0; i  A의 인덱스를 넣고 차이가 2보다 작은 것들을 2 - c..
[BOJ] 14891번 톱니바퀴 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;int k, n, dir, res, cnt = 1;string s[5];bool flag[5];void rev (int idx, int d){ if (d == 1){ int tmp = s[idx][7]; for (int i = 7; i > 0; i--) s[idx][i] = s[idx][i - 1]; s[idx][0] = tmp; } else{ int tmp = s[idx][0]; for (int i = 1; i > s[i]; cin >> ..
[BOJ] 2504번 괄호의 값 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;string s; stack st;bool check(){ bool flag = true; for (int i = 0; i 0){ int k = st.top(); st.pop(); st.push(k - idx); } else st.push(-idx); } else{ int k = st.top(); st.pop(); st.pop(); if (!st.empty() && st.top() > 0..
[BOJ] 18115번 카드 놓기 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;const int MAX = 1000005;int arr[MAX];int main(){ FASTIO; deque dq; int n; cin >> n; for (int i = 0; i 0; i--){ int num; cin >> num; if (num == 1) { int idx = dq.front(); dq.pop_front(); arr[idx] = i; } else if (num == 2){ ..
[BOJ] 31802번 주기 함수 (Easy) #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;#define ll long longconst int MAXN = 100005;ll arr[MAXN];int main(){ FASTIO; ll p, a, b, q, res = 0, sum = 0; cin >> p; for (int i = 0; i > arr[i]; sum += arr[i]; } cin >> a >> b; q = (b - a) / p; b -= q * p; res += q * sum; if (a  1. [a, b]에서 주기만큼 먼저 계산해서 ..
[BOJ] 15276번 Palindrmoic Password #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;int main(){ FASTIO; string tmp(6, ' '); vector res; for (int i = 1; i > n; while(n--){ string s, t; cin >> s; int i = stoi(s); int min = 1e9; for (auto it : res){ if (min > abs(i - it)){ min = abs(i - it); t = to_strin..