2021年暑假康复性训练(Codeforces Round #731 (Div. 3))全题解(上)

简介: 2021暑假康复性训练Codeforces Round #731 (Div. 3)A Shortest Path with ObstacleB. Alphabetical StringsC. Pair ProgrammingD. Co-growing SequenceE. Air ConditionersF. Array Stabilization (GCD version)G. How Many Paths?

2021暑假康复性训练


Codeforces Round #731 (Div. 3)

A Shortest Path with Obstacle


20210712232638333.png

input


7
1 1
3 3
2 2
2 5
2 1
2 3
1000 42
1000 1
1000 1000
1 10
3 10
2 10
3 8
7 8
3 7
2 1
4 1
1 1
1 344
1 10
1 1


output


4
6
41
4
4
2
334


2021071223275714.png


code:


int main()
{
    int _ = read;
    while(_ --){
        int x1 = read,y1 = read;
        int x2 = read,y2 = read;
        int tx1 = read,ty1 = read;
        int ans = abs(x1 - x2) + abs(y1 - y2);
        if(x1 == x2 && x2 == tx1 && ty1 >= min(y1,y2) && ty1 <= max(y2,y1)) ans += 2;
        if(y1 == y2 && y2 == ty1 && tx1 >= min(x1,x2) && tx1 <= max(x1,x2)) ans += 2;
        printf("%d\n",ans);
    }
    return 0;
}


B. Alphabetical Strings


20210712232918661.png


input


11
a
ba
ab
bac
ihfcbadeg
z
aa
ca
acb
xyz
ddcba


output:


YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO


Note


The example contains test cases from the main part of the condition.


code:


int main()
{
    int _ = read;
    while(_ --){
        char str[100];
        cin >> (str + 1);
        int len = strlen(str + 1);
        int l = 1,r = len;
        int flag = 0;
        for(int i = len;i >= 1;i--){
            char c = i + 96;
            if(c == str[l]) l ++;
            else if(c == str[r]) r --;
            else flag = 1;
        }
        if(flag) puts("NO");
        else puts("YES");
    }
    return 0;
}
/**
**/


C. Pair Programming


20210712233126663.png


input:


5
3 2 2
2 0
0 5
4 3 2
2 0 5
0 6
0 2 2
1 0
2 3
5 4 4
6 0 8 0
0 7 0 9
5 4 1
8 7 8 0
0


output:


2 0 0 5 
0 2 0 6 5 
-1
0 6 0 7 0 8 0 9
-1
int main()
{
    int _ = read;
    while(_ --){
        int k = read,n = read,m = read;
        for(int i=1;i<=n;i++) a[i] = read;
        for(int i=1;i<=m;i++) b[i] = read;
        int p1 = 1,p2 = 1;
        vector<int> vet;
        int flag = 0;
        while(p1 <= n || p2 <= m){
            if(p1 <= n && a[p1] <= k){
                if(a[p1] == 0) k++;
                vet.push_back(a[p1]);
                p1 ++;
            }
            else if(p2 <= m && b[p2] <= k){
                if(b[p2] == 0) k ++;
                vet.push_back(b[p2]);
                p2 ++;
            }
            else{
                flag = 1;
                break;
            }
        }
        if(flag) puts("-1");
        else{
            int siz = n + m;
            for(int i=1;i<=siz;i++){
                printf("%d ",vet[i-1]);
            }puts("");
        }
    }
    return 0;
}







目录
相关文章
|
5月前
|
C++ 容器
【PAT甲级 - C++题解】1025 PAT Ranking
【PAT甲级 - C++题解】1025 PAT Ranking
59 0
|
存储 C语言 C++
【PAT甲级 - C++题解】1012 The Best Rank
【PAT甲级 - C++题解】1012 The Best Rank
46 0
|
C++ 容器
【PAT甲级 - C++题解】1141 PAT Ranking of Institutions
【PAT甲级 - C++题解】1141 PAT Ranking of Institutions
80 0
|
人工智能
【训练题解】UPC Card Eater (思维)
【训练题解】UPC Card Eater (思维)
42 0
2021年暑假康复性训练(Codeforces Round #731 (Div. 4))全题解(下)
D. Co-growing Sequence input: output: code: E. Air Conditioners input: output: F. Array Stabilization (GCD version) input: output: code: G. How Many Paths? input: output: ac_code:
117 0
2021年暑假康复性训练(Codeforces Round #731 (Div. 4))全题解(下)