본문 바로가기
SWEA

[SWEA] 11688. Calkin-Wilf tree 1

by 콩순이냉장고 2021. 8. 11.

문제 URL : https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&problemLevel=3&contestProbId=AXgZSOn6ApIDFASW&categoryId=AXgZSOn6ApIDFASW&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=1 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

문제 접근법 : 간단합니다 L일경우 b=a+b R일경우 a=a+b만 하면됩니다.

 

소스코드 : 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <bits/stdc++.h>
using namespace std;
string s;
void input() {
    cin >> s;
}
 
void solve() {
    int ldata[100= { 1 };
    int rdata[100= { 1 };
    int l = 0;
    int r = 0;
    for (char c : s) {
        if (c == 'L')
            rdata[r + 1= ldata[l] + rdata[r++];
        else
            ldata[l + 1= ldata[l+++ rdata[r];
    }
    cout << ldata[l] << " " << rdata[r] << "\n";
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    int test;
    cin >> test;
    for (int i = 1; i <= test; i++) {
        input();
        cout << "#" << i << " ";
        solve();
    }
}
cs

 

 

궁금한점 혹은 모르는점 어떤 질문이든 댓글은 언제나 환영입니다.

'SWEA' 카테고리의 다른 글

[SWEA] 11315. 오목 판정  (0) 2021.08.12
[SWEA] 1979. 어디에 단어가 들어갈 수 있을까  (0) 2021.08.12
[SWEA] 1974. 스도쿠 검증  (0) 2021.08.03
[SWEA] 2001 파리 퇴치  (0) 2021.08.02
[SWEA] 2007 패턴 마디의 길이  (0) 2021.08.02