WookjeBlog
    • 블로그
    • 소개
    • 태그
    • 수업/강의
    • 라이브러리

    Wookje blog

    알고리즘 블로그였던 것

    Featured Posts
    • [BOJ] 1026 : 보물

      1026 : 보물 풀이 하나는 오름차순, 하나는 내림차순으로 정렬하고 곱해주면 된다! 코드 #include <stdio.h> #include <algorithm> int main() { int n, i, a[101], b[101], c = 0; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < n; i++) scanf("%d", &b[i]); std::sort(a, a + n); std::sort(b, b + n, [](const int &i, const int &j){return i > j;}); for (i = 0; i < n; i++) c...

      boj sort

      wookje.kwon's profile image

      wookje.kwon

      2017-03-13 14:40

    • [BOJ] 1012 : 유기농 배추

      1012 : 유기농 배추 풀이 DFS를 돌리자. 코드 #include <stdio.h> #include <memory.h> const int dx[] = { 0,0,-1,1 }; const int dy[] = { -1,1,0,0 }; int tc, n, m, k, i, j, x, y, ans; bool farm[52][52]; void dfs(int x, int y) { farm[x][y] = 0; for (int i = 0; i < 4; i++) if (farm[x + dx[i]][y + dy[i]]) dfs(x + dx[i], y + dy[i]); } int main() { scanf("%d", &tc); while...

      boj bfs dfs

      wookje.kwon's profile image

      wookje.kwon

      2017-03-13 11:41

    • [BOJ] 2623 : 음악프로그램

      2623 : 음악프로그램 풀이 위상정렬을 하면 된다! 코드 #include <iostream> #include <vector> using namespace std; const int n_ = 1000 + 3; int n, m, idg[n_]; vector<int> ans; vector<int> edg[n_]; void dfs(int now) { idg[now] = -1; ans.push_back(now); for (auto nxt : edg[now]) if (!(--idg[nxt])) dfs(nxt); } int main() { int i, j, a, b, c; cin >> n >> m; while (m--) { cin >> a >> b; while (--a) { cin >> c;...

      boj koi dfs bfs topological-sort

      wookje.kwon's profile image

      wookje.kwon

      2017-03-13 11:19

    • [BOJ] 2511 : 카드놀이

      2511 : 카드놀이 풀이 구현을 하자. 코드 #include <bits/stdc++.h> using namespace std; int a[10], b[10], i, A, B, p; int main() { for (i = 0; i < 10; i++) scanf("%d", &a[i]); for (i = 0; i < 10; i++) scanf("%d", &b[i]); for (i = 0; i < 10; i++) { if (a[i] > b[i]) A += 3, p = 0; else if (a[i] < b[i]) B += 3, p = 1; else A++, B++;...

      boj koi naive

      wookje.kwon's profile image

      wookje.kwon

      2017-03-13 09:20

    • [BOJ] 1509 : 팰린드롬 분할

      1509 : 팰린드롬 분할 풀이 나중에 써야징 코드 #include <stdio.h> #include <string.h> const int n_ = 2500 + 5; int len, dp[n_][n_], res[n_]; char data[n_]; int main() { scanf("%s", data); len = strlen(data); for (int i = 1; i <= len; i++) dp[i][i] = 1; for (int i = 1; i <= len - 1; i++) if (data[i - 1] == data[i]) dp[i][i + 1] = 1; for (int i = 2; i <= len...

      boj dynamic-programming

      wookje.kwon's profile image

      wookje.kwon

      2017-03-13 09:09

    • [BOJ] 10828 : 스택

      10828 : 스택 풀이 스택을 쓰자. 코드 #include <bits/stdc++.h> using namespace std; int n, a; stack<int> sta; string str; int main() { for (scanf("%d", &n); n; n--) { cin >> str; if (str == "push") { scanf("%d", &a); sta.push(a); } else if (str == "pop") { if (sta.empty()) printf("-1\n"); else printf("%d\n", sta.top()), sta.pop(); } else if (str == "size") { printf("%d\n", sta.size()); } else if (str == "empty") { printf("%d\n", sta.empty()); } else { if...

      boj koi stack

      wookje.kwon's profile image

      wookje.kwon

      2017-03-13 09:09

    • [BOJ] 13308 : 주유소

      13308 : 주유소 풀이 2016 koi 전국대회 2번 문제이다. 뭔가 코드가 dp인 것 같기도 하고 아닌 것 같기도 한데 어쨌든 다익스트라+dp 그런 느낌으로 풀었다. 음 생각해보니 dp가 맞네 dp[i][j] = 노드i에서 기름값j로 놓고 풀면 된다! 여기서 트릭(?)을 한 번 써보자. priority_queue에서 dst가 가장 작은 노드부터 꺼내기 때문에 dp[i][j] (== vst[i][j])에 방문했었다면 이미 지금보다 작은 값으로 방문했었음이 보장된다. 그래서 bfs 돌릴 때랑 똑같이 풀면 된다. visted면 방문하지 않아도 된다. 코드 #include <bits/stdc++.h> using namespace std; typedef...

      boj koi dijkstra dynamic-programming

      wookje.kwon's profile image

      wookje.kwon

      2017-03-10 12:26

    • [BOJ] 11866 : 조세퍼스 문제 0

      11866 : 조세퍼스 문제 0 풀이 단순 구현 코드 #include <bits/stdc++.h> using namespace std; int n, m, pos; vector<int> a; int main() { cin >> n >> m; for (int i = 0; i < n; i++) a.push_back(i + 1); printf("<"); while (1) { pos = (pos + m - 1) % a.size(); if (a.size() > 1) { printf("%d, ", a[pos]); } else { printf("%d>", a[pos]); break; } a.erase(a.begin() + pos); } return 0; }...

      boj naive

      wookje.kwon's profile image

      wookje.kwon

      2017-03-09 22:52

    • [BOJ] 4963 : 섬의 개수

      4963 : 섬의 개수 풀이 dfs를 돌리자 코드 #include <stdio.h> const int dx[] = { 0,0,1,-1,1,1,-1,-1 }; const int dy[] = { -1,1,0,0,1,-1,-1,1 }; int n, m; int a[51][51]; void dfs(int x, int y) { a[x][y] = 0; for (int i = 0; i < 8; i++) { int nx = x + dx[i], ny = y + dy[i]; if (nx < 0 || nx >= n || ny < 0 || ny >= m)...

      boj dfs

      wookje.kwon's profile image

      wookje.kwon

      2017-03-08 15:54

    • [BOJ] 10799 : 쇠막대기

      10799 : 쇠막대기 풀이 괄호가 나오는 문제는 대부분 stack을 이용하면 풀린다! 룰루랄라 코드 #include <bits/stdc++.h> using namespace std; int cnt, ans; string str; int cmp(char a, char b) { a -= '(', b -= '('; if (a == 0 && b == 0) return 1; if (a == 0 && b == 1) return 2; if (a == 1 && b == 0) return 3; if (a == 1 && b == 1) return 4;...

      boj koi stack

      wookje.kwon's profile image

      wookje.kwon

      2017-03-08 14:06

    • Previous Page
    • 39
    • 40
    • 41
    • 42
    • 43
    • Next Page
    • github
    • facebook
    • rss

    Copyright © Wookje Kwon. All rights reserved.