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

    Wookje blog

    알고리즘 블로그였던 것

    Featured Posts
    • [BOJ] 1713 : 후보 추천하기

      1713 : 후보 추천하기 풀이 짜라는대로 짜면 된다. 코드 #include <cstdio> #include <deque> #include <algorithm> using namespace std; int n, m; struct abc { int idx, vote, time; bool operator <(abc a)const { if (vote == a.vote) return time < a.time; return vote < a.vote; } }; int main() { deque<abc> d; scanf("%d %d", &m, &n); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); for (abc &it : d)...

      boj koi naive

      wookje.kwon's profile image

      wookje.kwon

      2018-09-17 12:13

    • [BOJ] 16120 : PPAP

      16120 : PPAP 풀이 일반적인 괄호 문자열 문제랑 비슷하게 해결하면 된다. 코드 #include <cstdio> int t; char a[1000003], s[1000003]; int ppap() { if (t < 4) return 0; if (s[t-4]=='P'&&s[t-3]=='P'&&s[t-2]=='A'&&s[t-1]=='P') return 1; return 0; } int main() { scanf("%s", a); int cnt = 0; for (int i = 0; a[i]; i++) { s[t++] = a[i]; while (ppap()) t -= 4, s[t++] = 'P'; } puts(t == 1 && s[0] == 'P' ? "PPAP" : "NP");...

      boj snupc stack

      wookje.kwon's profile image

      wookje.kwon

      2018-09-14 18:09

    • [BOJ] 16118 : 달빛 여우

      16118 : 달빛 여우 풀이 다익스트라 짜면서 사람들이 많이 놓치는 부분이 있는데 if (dp[now] != current_sum) continue; 위와 같은 동작을 넣은 코드와 그렇지 않은 코드의 시간복잡도가 다르다. (자세히는 모름) 이 문제의 경우, 데이터가 엄청 빡세서 저 동작을 넣어주지 않으면 시간 초과를 받게 된다. 아래의 코드를 참고하자. 코드 #include <cstdio> #include <vector> #include <queue> #include <algorithm> using namespace std; typedef long long ll; int n, m; struct edg { int idx, cnt; ll dst; bool operator...

      boj snupc dijkstra

      wookje.kwon's profile image

      wookje.kwon

      2018-09-14 18:08

    • [BOJ] 16113 : 시그널

      16113 : 시그널 풀이 잘 짜면 된다 코드 #include <cstdio> #include <cstring> int n, r[100003]; char a[100003], s[20005][5]; int isone(int x) { for (int i = 0; i < 5; i++) if (s[x][i] == '.' || s[x+1][i] == '#') return 0; return 1; } int count(int x) { int ret = 0; for (int i = x; i < x+3; i++) for (int j = 0; j < 5; j++) ret += s[i][j] == '.';...

      boj snupc string naive

      wookje.kwon's profile image

      wookje.kwon

      2018-09-14 18:07

    • [BOJ] 16112 : 5차 전직

      16112 : 5차 전직 풀이 메이플스토리~~ 코드 #include <cstdio> #include <algorithm> int n, k, a[300003]; long long r, s; int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) scanf("%d", &a[i]); std::sort(a, a+n); for (int i = n-1; i >= 0; i--) { if (i < k) r += s; s += (long long)a[i]; } printf("%lld", r); return 0; } 아무말 백준, 백준 온라인 저지, BOJ, Baekjoon Online Judge,...

      boj snupc naive

      wookje.kwon's profile image

      wookje.kwon

      2018-09-14 18:06

    • [BOJ] 15267 : Justified Jungle

      15267 : Justified Jungle 풀이 트리를 일단 나눴다면, 나눠진 후의 모든 컴포넌트에 속한 노드 수는 같아야 한다. 즉, 노드는 n의 약수로만 나눠질 수 있다. 100만 이하 자연수의 약수 개수가 최대 240개니까 O(240*n) 잘 커팅하면 6초 안에 될 거 같은데 안 됨 흠… 아무튼 나이브하게는 안 돌아가므로 조금 더 생각을 해야한다. 트리를 돌며 gcd(서브트리의 노드 개수, n)의 개수를 세어주자. 음… 그냥 코드를 보는 게 더 빠르겠다. 코드 #include <cstdio> #include <vector> using namespace std; int n,...

      boj acm-icpc tree math dfs

      wookje.kwon's profile image

      wookje.kwon

      2018-09-14 18:05

    • [BOJ] 15264 : Gambling Guide

      15264 : Gambling Guide 풀이 1에서 N으로 가는 기댓값을 구해야 하는데 기댓값을 구할 수가 없다! 그러니까 N에서부터 1로, 거꾸로 가면서 구해주자. 코드 #include <cstdio> #include <vector> #include <queue> #include <algorithm> using namespace std; const int n_ = 3e5+3; int n, m, sdeg[n_]; double dp[n_], sdp[n_]; struct abc { int idx; double val; bool operator <(abc a)const { return val > a.val; } }; priority_queue<abc> pq; vector<int> gph[n_]; int main() { scanf("%d %d", &n, &m); for...

      boj acm-icpc dynamic-programming math dfs

      wookje.kwon's profile image

      wookje.kwon

      2018-09-14 18:04

    • [BOJ] 14961 : Untangling Chain

      14961 : Untangling Chain 풀이 가장 위, 가장 아래, 가장 오른쪽, 가장 왼쪽의 좌표를 기억해두자. 그리고 항상 그 좌표보다 한칸 더 위로 직선을 쏴주자. 혹은 내 코드처럼 같은 방향(시계, 반시계)으로 두 번 이상 전진하는 경우로 접근해도 된다. 코드 #include <cstdio> int n, i, now, prv; int main() { scanf("%d", &n); for (i = 1; i <= n; i++) { printf("%d ", now-prv ? 1 : i); prv = now; scanf("%d %d", &now, &now); } return...

      boj acm-icpc idea naive

      wookje.kwon's profile image

      wookje.kwon

      2018-09-14 18:03

    • [BOJ] 15991 : 1, 2, 3 더하기 6

      15991 : 1, 2, 3 더하기 6 풀이 둠칫타칫 코드 #include <cstdio> const int m = 1e9+9; int n, t, d[55555]={0,1,1,2,4}; int main() { for (int i = 5; i <= 55555; i++) { d[i] = ((long long)d[i-1]+d[i-2]+d[i-3]) % m; } for (scanf("%d", &t); t--;) { scanf("%d", &n); printf("%d\n", (d[n/2+1] + d[n/2]) % m); } return 0; } 아무말 백준, 백준 온라인 저지, BOJ, Baekjoon Online Judge, C, C++, 씨, 씨쁠쁠, JAVA, algorithm, 자바, 알고리즘,...

      boj dynamic-programming

      wookje.kwon's profile image

      wookje.kwon

      2018-09-09 23:00

    • [BOJ] 15990 : 1, 2, 3 더하기 5

      15990 : 1, 2, 3 더하기 5 풀이 계단오르기 아니면 RGB거리 문제랑 비슷하게 풀면 된다 코드 #include <cstdio> const int m = 1e9+9; int n, t, d[3][100001]; int main() { d[0][1] = d[1][2] = d[0][3] = d[1][3] = d[2][3] = 1; for (int i = 4; i <= 100000; i++) { d[0][i] = (d[1][i-1]+d[2][i-1])%m; d[1][i] = (d[0][i-2]+d[2][i-2])%m; d[2][i] = (d[0][i-3]+d[1][i-3])%m; } for (scanf("%d", &t); t--;) { scanf("%d", &n); printf("%lld\n", ((long long)d[0][n]+d[1][n]+d[2][n])%m); } return 0; }...

      boj dynamic-programming

      wookje.kwon's profile image

      wookje.kwon

      2018-09-07 16:34

    • Previous Page
    • 9
    • 10
    • 11
    • 12
    • 13
    • Next Page
    • github
    • facebook
    • rss

    Copyright © Wookje Kwon. All rights reserved.