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

    Wookje blog

    알고리즘 블로그였던 것

    Featured Posts
    • [BOJ] 8094 : Canoes

      8094 : Canoes 풀이 투포인터(?) 같은 느낌으로 그리디하게 풀어주자. 각 카누들의 용량(?)을 정렬해주자. 정렬 후 배열의 양 끝에는 min, max 값이 들어있으므로 양 사이드에서 가운대로 포인터를 옮기며 매칭할 수 있다면 매칭해주자. 코드 #include <cstdio> #include <algorithm> int n, w, i, j, a[30003]; int main() { scanf("%d %d", &w, &n); for (; j<n; j++) scanf("%d", &a[j]); std::sort(a, a+n); for (j = n-1; j && i<j; j--) if (a[i]+a[j]<=w) i++; printf("%d", n-i); return 0; } 아무말 백준,...

      boj poi two-pointer

      wookje.kwon's profile image

      wookje.kwon

      2018-09-27 13:29

    • [BOJ] 8983 : 사냥꾼

      8983 : 사냥꾼 풀이 어떤 동물을 사냥할 수 있는지 판단해야한다. 그러기 위해선 어떤 동물에서 가장 가까운 어떤 사냥대를 찾아야 한다. 동물의 y좌표는 모든 사냥대에 대해 절대적인 반면, x좌표는 사냥대에 대해 상대적이다. 그러므로 동물의 x좌표와 사냥대의 x좌표만 비교해서 O(1) 또는 O(log n)의 시간에 가장 가까운 사냥대를 찾을 수 있다. O(1)은 적당히 반복문을 잘 굴리면 되고 O(log n)은 적당히 이분탐색 같은 걸 사용하면 된다. (안 해봤지만 아마 될 거다 ㅎ) 코드 #include <cstdio> #include <algorithm> using namespace...

      boj koi naive line-sweep

      wookje.kwon's profile image

      wookje.kwon

      2018-09-18 22:56

    • [BOJ] 15633 : Fan Death

      15633 : Fan Death 풀이 답에서 *5-24하면 되는데 왜 그러는지 모름 ㅋㅋ 코드 #include <cstdio> int n, r; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { if (n % i == 0) r += i; } printf("%d", r*5-24); return 0; } 아무말 백준, 백준 온라인 저지, BOJ, Baekjoon Online Judge, C, C++, 씨, 씨쁠쁠, JAVA, algorithm, 자바, 알고리즘, 자료구조, 문제, 문제 풀이, 풀이

      boj naive

      wookje.kwon's profile image

      wookje.kwon

      2018-09-17 12:30

    • [BOJ] 15748 : Rest Stops

      15748 : Rest Stops 풀이 그리디하게 풀면 된다. 가장 큰 값까지 간 다음 가능한 시간 동안 계속 풀을 뜯어 먹는다. 그리고 이후의 값들 중 가장 큰 값을 찾고 이 동작을 반복한다. 코드 #include <cstdio> #include <algorithm> long long l, n, r, f, b, x[100003], c[100003]; int main() { scanf("%lld %lld %lld %lld", &l, &n, &f, &b); for (int i = 1; i <= n; i++) scanf("%lld %lld", &x[i], &c[i]); for (int i = n; i...

      boj usaco greedy

      wookje.kwon's profile image

      wookje.kwon

      2018-09-17 12:26

    • [BOJ] 15368 : Birokracija

      15368 : Birokracija 풀이 트리에 존재하는 모든 노드에 대해, 각각의 노드에서 루트까지의 거리를 더하는 문제이다. 음… 그냥 짜면 된다. 코드 #include <cstdio> int n, par[200002], cnt[200002]; long long ans[200002]; int main() { scanf("%d", &n); for (int i = 2; i <= n; i++) scanf("%d", &par[i]); for (int i = n; i >= 1; i--) { ans[par[i]] += ++ans[i] + ++cnt[i]; cnt[par[i]] += cnt[i]; } for (int i = 1; i <= n; i++) printf("%lld ",...

      boj coci tree naive dfs

      wookje.kwon's profile image

      wookje.kwon

      2018-09-17 12:25

    • [BOJ] 15367 : Spirale

      15367 : Spirale 풀이 달.팽.이.조.아.!.! 코드 #include <cstdio> #include <algorithm> const int dx[2][4] = { {0,-1,0,1},{0,-1,0,1} }; const int dy[2][4] = { {-1,0,1,0},{1,0,-1,0} }; int n, m, k; int a[500][500]; int main() { scanf("%d %d %d", &n, &m, &k); while (k--) { int x, y, c, num = 1, cnt = 2, dir = 0; scanf("%d %d %d", &x, &y, &c); x += 249, y += 249; if (!a[x][y]) a[x][y] = 1; while (dir <...

      boj coci naive

      wookje.kwon's profile image

      wookje.kwon

      2018-09-17 12:24

    • [BOJ] 15366 : Olivander

      15366 : Olivander 풀이 정.렬.조.아 코드 #include <cstdio> #include <algorithm> using namespace std; int n, a[100], b[100]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) scanf("%d", &b[i]); sort(a, a + n); sort(b, b + n); while (n--) if (a[n] > b[n]) return !printf("NE"); return !printf("DA"); } 아무말 백준, 백준 온라인 저지, BOJ, Baekjoon Online Judge, C, C++, 씨,...

      boj coci sort naive

      wookje.kwon's profile image

      wookje.kwon

      2018-09-17 12:23

    • [BOJ] 15998 : 카카오머니

      15998 : 카카오머니 풀이 주어지는 입력을 a[i], b[i]라고 하자. b[i]-b[i-1] == a[i]인 경우는 돈을 뽑아서 쓰지 않는 정상적인(?) 경우이다. b[i]-b[i-1] != a[i]인 경우는 비정상적인(?) 경우이다. 여기서 비정상적인(?) 경우도 두 경우로 나뉜다. 하나는 인출하지 않는 상황에서 남은 금액이 맞지 않는 경우, 이건 그냥 짜주자. 인출하는 경우에, 은행에서 인출하는 금액 k는 b[i]-b[i-1]-a[i]이다. 오 그렇다면 이러한 k가 여러개 있을 수 있는데, 우리가 구하는 건 공통된 k이므로 이러한 k들의 gcd를 구해주자. 그러한 gcd 값을 gcd_k라고 하자. 그럼 답이 모순되는...

      boj code-festival math naive gcd

      wookje.kwon's profile image

      wookje.kwon

      2018-09-17 12:22

    • [BOJ] 4256 : 트리

      4256 : 트리 풀이 어찌저찌 트리 다시 만들고 잘 짜면 된다. 풀이가 너무 부실한데? 다음의 예제를 보자. 8 3 6 5 4 8 7 1 2 5 6 8 4 3 1 2 7 예를 들어, 지금 inorder로 3을 보고 있다면 preorder 기준으로 3을 반으로 나누면 5 6 8 4, 1 2 7이 있다. 이 말은 노드3에 대해, 5 6 8 4는 왼쪽, 1 2 7은 오른쪽 서브트리 노드들이라는 뜻이다. 이제 이를 토대로 쭉 짜보자....

      boj acm-icpc tree

      wookje.kwon's profile image

      wookje.kwon

      2018-09-17 12:21

    • [BOJ] 3758 : KCPC

      3758 : KCPC 풀이 주어진 조건대로 정렬해서 구현하면 된다. 코드 #include <bits/stdc++.h> using namespace std; struct abc { int sco, sub, tim, idx; bool operator <(abc a)const { if (sco == a.sco) { if (sub == a.sub) { return tim < a.tim; } return sub < a.sub; } return sco > a.sco; } }; int main() { int tc; scanf("%d", &tc); while (tc--) { int n, k, t, m; abc a[103][103]; memset(a, 0, sizeof(a)); scanf("%d...

      boj acm-icpc sort naive

      wookje.kwon's profile image

      wookje.kwon

      2018-09-17 12:20

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

    Copyright © Wookje Kwon. All rights reserved.