Post

Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) 후기

- Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) 후기

Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine)) 후기

A. Simply Strange Sort

풀이 보기

풀이

풀이가 없다. 이거 시뮬레이션 문제라서, 문제에서 원하는대로만 구현하면 된다..

코드

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
 
typedef char bool;
const bool true = 1;
const bool false = 0;
 
#define M 1000
 
int arr[M];
int n;
 
bool sorted() {
    bool a = true;
    for (int i = 0; i < n - 1; ++i) {
        a &= (arr[i] < arr[i + 1]);
    }
    return a;
}
 
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        for (int i = 0; i < n; ++i) {
            scanf("%d", arr + i);
        }
        arr[n] = M;
 
        int ret;
        for (ret = 0;; ++ret) {
            if (sorted()) {
                break;
            }
 
            if (ret % 2 == 0) {
                for (int j = 0; j < n; j += 2) {
                    if (arr[j] > arr[j + 1]) {
                        int temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            } else {
                for (int j = 1; j < n; j += 2) {
                    if (arr[j] > arr[j + 1]) {
                        int temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            }
        }
 
        printf("%d\n", ret);
    }
    return 0;
}

결과

ContestStart timeRankSolvedRating changeNew rating
#740 (Div. 2, based on VK Cup 2021 - Final (Engine))2021/8/24 23:3551621-551366
This post is licensed under CC BY 4.0 by the author.