본문 바로가기
알고리즘/시뮬레이션

1592 영식이와 친구들

by tryotto 2020. 1. 15.
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
#include <stdio.h>
 
int main() {
    int n, m, l;
    scanf("%d %d %d"&n, &m, &l);
 
    int cnt = 0, maxN = -1, cur = 1;
    int chk[1005= { 0 };
    chk[1= 1;
 
    while (1) {
        if (maxN == m)
            break;
 
        if (chk[cur] % 2 == 1) {
            cur += l;
            if (cur > n)
                cur -= n;            
        }
        else {
            cur -= l;
            if (cur <= 0)
                cur += n;
        }
        chk[cur]++;
 
        if (chk[cur] > maxN)
            maxN = chk[cur];
 
        cnt++;
    }
    printf("%d", cnt);
}
cs


'알고리즘 > 시뮬레이션' 카테고리의 다른 글

1966 프린터 큐  (0) 2021.01.03
2979 트럭 주차  (0) 2020.01.15
2164 카드2  (0) 2020.01.15
1547 공  (0) 2020.01.15
2161 카드1  (0) 2020.01.15