JXNVCE ALGO-LOG YouJin Jung

BOJ-2630

λΆ„ν•  정볡 with πŸŒˆπŸŽ¨πŸ“‘

#include <iostream>

using namespace std;

int map[130][130];
int b = 0, w = 0;

void sol(int x, int y, int len){
    int tmp = 0;
    for(int i = x; i < x + len; i++){
        for(int j = y; j < y + len; j++){
            if(map[i][j]) tmp++;
        }
    }

    if(!tmp) w++;
    else if(tmp == len * len) b++;
    else{
        solution(x, y, len / 2);
        solution(x + len / 2, y, len / 2);
        solution(x, y + len / 2, len / 2);
        solution(x + len / 2, y + len / 2, len / 2);
    }
    return;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int num;
    cin >> num;

    for(int i = 1; i <= num; i++){
        for(int j = 1; j <= num; j++)
            cin >> map[i][j];
    }

    sol(1, 1, num);
    cout << w << "\n"; 
    cout << b << "\n";
    return 0;
}

BOJ-1934

μœ ν΄λ¦¬λ“œλ₯Ό μ΄μš©ν•œ μ΅œμ†Œκ³΅λ°°μˆ˜ κ΅¬ν•˜κΈ° 방식! μ΅œλŒ€κ³΅μ•½μˆ˜λ₯Ό ν™œμš©ν•œλ‹€.

#include<iostream>
 
using namespace std;
 
int divide(int x, int y) {
    if (x%y==0) return y;
    else return divide(y, x%y);
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    int T, A, B;
    cin >> T;
 
    for (int i=0; i<T; i++) {
        cin >> A >> B;
        if (A>=B) {
            cout << A*B/divide(A,B) << "\n";
        }
        else
            cout << A*B/divide(B,A) << "\n"; 
    }
    return 0;
}

BOJ-11654

ν˜• λ³€ν™˜, μ•„μŠ€ν‚€ μ½”λ“œ κ΄€λ ¨ μ•„μ£Ό κ°„λ‹¨ν•œ 문제!πŸ˜‚

#include <iostream>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    char in;
    cin >> in;
    cout << int(in) << endl;    
}

image

BOJ-9461

λ²”μœ„ κ³ λ €ν•˜κΈ°β€¦ μ˜€λ²„ν”Œλ‘œμš° μ‘°μ‹¬ν•˜κΈ°! 이번 κΈ°νšŒμ— ν”Όλ³΄λ‚˜μΉ˜λž‘ λΉ„μŠ·ν•œ νŒŒλ‚˜λ„λ°˜μˆ˜μ—΄μ„ μ•Œκ²Œ λ˜μ—ˆλ‹€.

Panadovan Sequence
P(n) = P(n-2) + P(n-3)
P(0) = P(1) = P(2) = 1 
  • κ΅¬κΈ€μ—μ„œ ν•΄λ‹Ή μˆ˜μ—΄μ— λŒ€ν•œ 점화식을 μ•Œκ²Œ λ˜μ—ˆκ³ ,
  • λ°±μ€€ 질문 닡변을 톡해 μ™œ ν‹€λ ΈλŠ”μ§€ μ•Œ 수 μžˆμ—ˆλ‹€. => int λŒ€μ‹  long을 μΌλ”λ‹ˆ, ν•΄κ²°! κΈ°ν•˜κΈ‰μˆ˜μ μœΌλ‘œ μ»€μ§€λŠ” 숫자λ₯Ό 항상 μœ λ…ν•˜μžβ€¦βš 
#include<iostream>

using namespace std;

long input[101];

long panadovan(int n) {
    long ppp = 1, pp = 1, p = 1, pn = 1;
    for (int i=3; i<=n; i++) {
        pn = ppp+pp;
        ppp = pp;
        pp = p;
        p = pn;
    }
    return pn;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int T;
    cin >> T;

    for (int i=0; i<T; i++) 
        cin >> input[i];
    for (int i=0; i<T; i++) 
        cout << panadovan(input[i]-1) << endl;
    return 0;
}

image

BOJ-3036

#include<iostream>

using namespace std;

int arr[101];

int get_gcd(int a, int b) {
	if (b == 0) return a;
	return get_gcd(b, a % b);
}

int main() {
    ios::sync_with_stdio(false);
    cout.tie(NULL); cin.tie(NULL);
    int N, gcd;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> arr[i];
    }
	for (int i = 1; i < N; i++) {
		gcd = get_gcd(arr[0], arr[i]);
		cout << arr[0] / gcd << "/" << arr[i] / gcd << endl;
	}
    return 0;
}

image