'Algorithm/Problem Solving'에 해당되는 글 41건

  1. 2020.04.29 :: [BOJ/2745] 진법 변환
  2. 2020.04.27 :: [BOJ/11005] 진법 변환 2
  3. 2020.04.23 :: [BOJ/9613] GCD 합
  4. 2020.04.23 :: [BOJ/1934] 최소공배수
  5. 2020.04.23 :: [BOJ/2609] 최대공약수와 최소공배수
  6. 2020.04.22 :: [BOJ/10430] 나머지
  7. 2020.04.22 :: [BOJ/2011] 암호코드
  8. 2020.04.22 :: [BOJ/2225] 합분해
  9. 2020.04.22 :: [BOJ/9461] 파도반 수열
  10. 2020.04.22 :: [BOJ/2133] 타일 채우기
Algorithm/Problem Solving 2020. 4. 29. 22:36

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/2745

 

사용 알고리즘

 

풀이

- B ^ k를 곱하면서 더함

 

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/2745.cpp

#include <iostream>
#include <string>
 
using namespace std;
 
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string n; int b; cin >> n >> b;
    int ans = 0;
    int len = n.length(), temp = 1;
    for (int i = 0; i < len; ++i) {
        int num;
        if (n[i] >= '0' && n[i] <= '9') num = n[i] - '0';
        else num = n[i] - 55;
        ans *= b;
        ans += num;
    }
    cout << ans << '\n';
    return 0;
}

Colored by Color Scripter

cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/1212] 8진수 2진수  (0) 2020.05.12
[BOJ/1373] 2진수 8진수  (0) 2020.05.11
[BOJ/11005] 진법 변환 2  (0) 2020.04.27
[BOJ/9613] GCD 합  (0) 2020.04.23
[BOJ/1934] 최소공배수  (0) 2020.04.23
posted by DevMoomin
:
Algorithm/Problem Solving 2020. 4. 27. 23:06

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/11005

 

사용 알고리즘

 

풀이

- N이 0이 될 때까지 B로 나누며 나머지를 계속해서 구함

 

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/11005.cpp

#include <cstdio>
#include <vector>
 
using namespace std;
 
int main(void) {
    int n, b; scanf("%d %d"&n, &b);
    vector<int> v;
    while (1) {
        if (n == 0break;
        v.push_back(n % b);
        n /= b;
    }
    int len = v.size();
    for (int i = len - 1; i >= 0--i) {
        if (v[i] >= 0 && v[i] <= 9printf("%d", v[i]);
        else printf("%c", v[i] + 55);
    }
    printf("\n");
    return 0;
}

Colored by Color Scripter

cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/1373] 2진수 8진수  (0) 2020.05.11
[BOJ/2745] 진법 변환  (0) 2020.04.29
[BOJ/9613] GCD 합  (0) 2020.04.23
[BOJ/1934] 최소공배수  (0) 2020.04.23
[BOJ/2609] 최대공약수와 최소공배수  (0) 2020.04.23
posted by DevMoomin
:
Algorithm/Problem Solving 2020. 4. 23. 22:38

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/9613

 

사용 알고리즘

- 유클리드 호제법

 

풀이

- GCD(A, B) = 유클리드 호제법

 

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/9613.cpp

#include <cstdio>
 
int arr[103];
 
int gcd(int num1, int num2) {
    if (num2 == 0return num1;
    return gcd(num2, num1 % num2);
}
 
int main(void) {
    int t; for (scanf("%d"&t); t--;) {
        int n; scanf("%d"&n);
        for (int i = 0; i < n; ++i) scanf("%d"&arr[i]);
        long long ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                ans += gcd(arr[i], arr[j]);
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Colored by Color Scripter

cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/2745] 진법 변환  (0) 2020.04.29
[BOJ/11005] 진법 변환 2  (0) 2020.04.27
[BOJ/1934] 최소공배수  (0) 2020.04.23
[BOJ/2609] 최대공약수와 최소공배수  (0) 2020.04.23
[BOJ/10430] 나머지  (0) 2020.04.22
posted by DevMoomin
:
Algorithm/Problem Solving 2020. 4. 23. 01:22

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/1934

 

사용 알고리즘

- 유클리드 호제법

 

풀이

- LCM(A, B) = A * B / GCD(A, B)

 

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/1934.cpp

#include <cstdio>
 
int gcd(int num1, int num2) {
    if (num2 == 0return num1;
    return gcd(num2, num1 % num2);
}
 
int main(void) {
    int t; for (scanf("%d"&t); t--;) {
        int a, b; scanf("%d %d"&a, &b);
        printf("%d\n", a * b / gcd(a, b));
    }
    return 0;
}

Colored by Color Scripter

cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/11005] 진법 변환 2  (0) 2020.04.27
[BOJ/9613] GCD 합  (0) 2020.04.23
[BOJ/2609] 최대공약수와 최소공배수  (0) 2020.04.23
[BOJ/10430] 나머지  (0) 2020.04.22
[BOJ/2011] 암호코드  (0) 2020.04.22
posted by DevMoomin
:
Algorithm/Problem Solving 2020. 4. 23. 00:19

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/2609

 

사용 알고리즘

- 유클리드 호제법

 

풀이

- GCD(A, B) = 유클리드 호제법

- LCM(A, B) = A * B / GCD(A, B)

 

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/2609.cpp

#include <cstdio>
 
int gcd(int num1, int num2) {
    if (num2 == 0return num1;
    return gcd(num2, num1 % num2);
}
 
int main(void) {
    int a, b; scanf("%d %d"&a, &b);
    int g = gcd(a, b); printf("%d\n", g);
    int l = a * b / g; printf("%d\n", l);
    return 0;
}

Colored by Color Scripter

cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/9613] GCD 합  (0) 2020.04.23
[BOJ/1934] 최소공배수  (0) 2020.04.23
[BOJ/10430] 나머지  (0) 2020.04.22
[BOJ/2011] 암호코드  (0) 2020.04.22
[BOJ/2225] 합분해  (0) 2020.04.22
posted by DevMoomin
:
Algorithm/Problem Solving 2020. 4. 22. 23:24

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/10430

 

사용 알고리즘

 

풀이

- 단순 출력

 

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/10430.cpp

#include <cstdio>
 
int main(void) {
    int a, b, c; scanf("%d %d %d"&a, &b, &c);
    printf("%d\n", (a + b) % c);
    printf("%d\n", ((a % c) + (b % c)) % c);
    printf("%d\n", (a * b) % c);
    printf("%d\n", ((a % c) * (b % c)) % c);
    return 0;
}

Colored by Color Scripter

cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/1934] 최소공배수  (0) 2020.04.23
[BOJ/2609] 최대공약수와 최소공배수  (0) 2020.04.23
[BOJ/2011] 암호코드  (0) 2020.04.22
[BOJ/2225] 합분해  (0) 2020.04.22
[BOJ/9461] 파도반 수열  (0) 2020.04.22
posted by DevMoomin
:
Algorithm/Problem Solving 2020. 4. 22. 23:04

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

https://www.acmicpc.net/problem/2011

 

사용 알고리즘

- DP

 

풀이

- d[i] = i번째 문자까지 해석했을 때 나올 수 있는 해석의 가짓수

- i - 1과 i를 붙였을 때 10 ~ 26인 경우, 

  d[i] = d[i - 1] + d[i - 2]

- i - 1과 i를 붙였을 때 10 ~ 26이 아닌 경우,

  d[i] = d[i - 1]

 

소스 코드

https://github.com/moomini/algorithm/blob/master/boj/2011.cpp

#include <cstdio>

#include <cstring>

 

int d[5003];

 

int main(void) {

    char pw[5003]; scanf("%s", pw + 1);

    int len = strlen(pw + 1);

    d[0= 1;

    for (int i = 1; i <= len; ++i) {

        int x = pw[i] - '0';

        if (1 <= x && x <= 9) d[i] += d[i - 1];

        if (i == 1continue;

        if (pw[i - 1== '0'continue;

        x = (pw[i - 1- '0'* 10 + (pw[i] - '0');

        if (10 <= x && x <= 26) {

            d[i] += d[i - 2];

            d[i] %= 1000000;

        }

    }

    printf("%d\n", d[len]);

    return 0;

}

Colored by Color Scripter

cs

 

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/2609] 최대공약수와 최소공배수  (0) 2020.04.23
[BOJ/10430] 나머지  (0) 2020.04.22
[BOJ/2225] 합분해  (0) 2020.04.22
[BOJ/9461] 파도반 수열  (0) 2020.04.22
[BOJ/2133] 타일 채우기  (0) 2020.04.22
posted by DevMoomin
:
Algorithm/Problem Solving 2020. 4. 22. 21:26

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/2225

 

사용 알고리즘

- DP

 

풀이

- d[k][n] = 0 ~ n 정수 k개를 더해서 합이 n이 되는 경우의 수

- d[k][n] += d[k - 1][n - l] (0 <= l <= n)

 

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/2225.cpp

#include <cstdio>
 
int d[203][203];
 
int main(void) {
    int n, k; scanf("%d %d"&n, &k);
    d[0][0= 1;
    for (int i = 1; i <= k; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int l= 0; l <= j; ++l) {
                d[i][j] += d[i - 1][j - l];
                d[i][j] %= 1000000000;
            }
        }
    }
    printf("%d\n", d[k][n]);
    return 0;
}
cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/10430] 나머지  (0) 2020.04.22
[BOJ/2011] 암호코드  (0) 2020.04.22
[BOJ/9461] 파도반 수열  (0) 2020.04.22
[BOJ/2133] 타일 채우기  (0) 2020.04.22
[BOJ/1699] 제곱수의 합  (0) 2020.04.20
posted by DevMoomin
:
Algorithm/Problem Solving 2020. 4. 22. 21:13

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/9461

 

사용 알고리즘

- DP

 

풀이

- d[i] = 파도반 수열의 i번째 값

- d[i] = d[i - 2] + d[i - 3]

 

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/9461.cpp

#include <cstdio>
 
long long d[103];
 
int main(void) {
    d[1= d[2= d[3= 1;
    for (int i = 4; i <= 100++i) d[i] = d[i - 3+ d[i - 2];
    int t; for (scanf("%d"&t); t--;) {
        int n; scanf("%d"&n);
        printf("%lld\n", d[n]);
    }
    return 0;
}

Colored by Color Scripter

cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/2011] 암호코드  (0) 2020.04.22
[BOJ/2225] 합분해  (0) 2020.04.22
[BOJ/2133] 타일 채우기  (0) 2020.04.22
[BOJ/1699] 제곱수의 합  (0) 2020.04.20
[BOJ/2579] 계단 오르기  (0) 2020.04.20
posted by DevMoomin
:
Algorithm/Problem Solving 2020. 4. 22. 01:16

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/2133

 

사용 알고리즘

- DP

 

풀이

- d[i] = 3 * i를 채우는 방법의 수

- d[i] = 3 * d[i - 2] + 2 * d[i - 4] + 2 * d[i - 6] + ...

아래 그림의 경우도 고려해야 한다.

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/2133.cpp

#include <cstdio>
 
int d[33];
 
int main(void) {
    int n; scanf("%d"&n);
    d[0= 1;
    for (int i = 2; i <= n; i += 2) {
        d[i] += (3 * d[i - 2]);
        for (int j = i - 4; j >= 0; j -= 2) d[i] += (2 * d[j]);
    }
    printf("%d\n", d[n]);
    return 0;
}

Colored by Color Scripter

cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/2225] 합분해  (0) 2020.04.22
[BOJ/9461] 파도반 수열  (0) 2020.04.22
[BOJ/1699] 제곱수의 합  (0) 2020.04.20
[BOJ/2579] 계단 오르기  (0) 2020.04.20
[BOJ/1912] 연속합  (0) 2020.04.19
posted by DevMoomin
: