티스토리 뷰

 

기업 코딩테스트에서 떨어지면 아마 마음아픈 구현력 때문에 떨어지지 않을까 싶다..

 

이 문제는 원숭이들이 한번씩은 무조건 같은팀이 안되도록 7일간의 팀을 출력하면 된다!

왜 7 일인지를 생각해보면 2^7 = 128 이고 n<=99 이므로

반씩 계속 잘라가면서 팀을 시켜주면 무조건 가능하다!

그래서 l~r까지 반은 A 반은 B를 계속 해주면 된다 l>=r 까지!!

이걸 구현을 계속 틀렸다 굿... 싸늘하다.... 극망의 기운이 날아와 가슴에 꽂힌다..

구현은 잘하자..!!

 

소스코드

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
35
36
#include <iostream>
#include <algorithm>
using namespace std;
 
char ans[7][111];
int n,cnt;
 
void solve(int l,int r,int dep){
    if(l >= r || dep==7return;
    cnt=max(cnt,dep);
    int mid = (l+r)/2;
    for(int i=l;i<=r;i++){
        if(i<=mid) ans[dep][i]='A';
        else ans[dep][i]='B';
    }
    solve(l,mid,dep+1);
    solve(mid+1,r,dep+1);
}
 
int main(){
    //freopen("input.txt","r",stdin);
    scanf(" %d",&n);
    solve(1,n,0);
    for(int i=0;i<=cnt;i++){
        for(int j=1;j<=n;j++){
            if(ans[i][j]=='\0') ans[i][j] = (j%2==0) ? 'A' : 'B';
            printf("%c",ans[i][j]);
        } puts("");
    }
    while(cnt != 6){
        for(int i=0;i<n;i++){
            if(i&1printf("A");
            else printf("B");
        } puts(""); cnt++;
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

'알고리즘 > BOJ' 카테고리의 다른 글

[백준] 17498 폴짝 게임  (0) 2019.11.08
[백준] 17497 계산기  (0) 2019.11.08
[백준] 16441 아기돼지와 늑대  (0) 2019.09.20
[백준] 16440 제이크와 케이크  (0) 2019.09.20
[백준] 16437 양 구출 작전  (0) 2019.09.20
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
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
글 보관함