> >
본문 바로가기

Algorithm/BOJ

(27)
[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..
[BOJ] 30445번 행복 점수 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;int main(){ FASTIO; string s; int ph = 0, pg = 0; getline(cin, s); for (int i = 0; i  - 부동 소수점 오차!
[BOJ] 14503번 로봇 청소기 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;const int MAXN = 55;int n, m, r, c, d, res;int arr[MAXN][MAXN];int dx[] = {-1, 0, 1, 0};int dy[] = {0, 1, 0, -1};bool boundary(int x, int y){ return x >= 0 && x = 0 && y > n >> m >> r >> c >> d; for (int i = 0; i > arr[i][j]; } } while(true){ if(!arr[r][c]){ arr[r]..
[BOJ] 2296번 건물짓기 #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;const int MAXN = 1005;int DP[2][MAXN];int n;vector, int>> v;void solved(int flag = false){ int k = 0; if (flag) { reverse(v.begin(), v.end()); k = 1; } for (int i = 0; i = 0; j--){ if (y1 > v[j].first.second){ DP[k][i] = max(DP[k][i], DP[k][j] + c); } ..
[BOJ] 4136번 Pousse #include #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)using namespace std;int n;bool flag;const int MAXN = 105;char arr[MAXN][MAXN];bool check() { int X = 0, O = 0; for (int i = 0; i O) { cout X) { cout 0; j--) arr[idx][j] = arr[idx][j - 1]; arr[idx][0] = c; } else if (dir == 'R'){ for (int i = n - 1; i >= 0; i--) ..