페이지

10804번: 카드 역배치

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


$O(n)$

#include<cstdio>
#include<algorithm>
int a[21];
int main() {
    for (int i = 1; i <= 20; i++) a[i] = i;
    for (int i = 0, x, y; i < 10; i++) {
        scanf("%d%d", &x, &y);
        std::reverse(a + x, a + y + 1);
    }
    for (int i = 1; i <= 20; i++) printf("%d ", a[i]);
    return 0;
}

댓글 없음 :

댓글 쓰기