【CodeForces】Codeforces Round 856 (Div. 2) A,B

简介: Problem - A - Codeforces

Problem - A - Codeforces 

9.3.png🚥🚥🚥


这道题的细节很妙(好像这就是cf的特点)


给出的2*n-2个字符串里面包含了前缀和和后缀


观察这2*n-2个字符串,我们会发现,其中有两个字符串的长度是n-1的


2个长度为n-1的字符串,那么这2个字符串就分别是前缀和后缀了


🚥🚥🚥

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t; 
    cin>>t;
    while(t--){
        int n; cin>>n;
        string s1, s2;
        for(int i=0; i<(2*n-2); i++){
            string s; 
            cin>>s;
            if(s.size() == n-1) s1 += s;
        }
        s2 += s1;
        reverse(s2.begin(), s2.end());
        if(s1 == s2) cout<<"YES"<<'\n';
        else cout<<"NO"<<'\n';
    }
}

Problem - B - Codeforces 

9.4.png

注意:任何数都可以除1,所以当a[i]=1时,把a[i]变成2

#include <iostream>
#include <vector>
using namespace std;
void solve(){
    int n;
     cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (long long i = 0; i < n; ++i) {
        if (a[i]==1) {
            a[i]=2;
        }
        if (i >0)
        while (a[i] % a[i-1] == 0) {
            a[i] ++;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << a[i] << " ";
    }
    cout << endl;
}
int main(){
    int t; 
    cin >> t;
    while(t--) 
    solve();
    return 0;
}

Code over!

相关文章
Codeforces Round #192 (Div. 2) (329A)C.Purification
Codeforces Round #192 (Div. 2) (329A)C.Purification
44 0
|
人工智能
Codeforces Round #786 (Div. 3)(A-D)
Codeforces Round #786 (Div. 3)(A-D)
71 0
【CodeForces】Codeforces Round 857 (Div. 2) B
【CodeForces】Codeforces Round 857 (Div. 2) B
129 0
Codeforces Round #723 (Div. 2)B. I Hate 1111
Description You are given an integer x. Can you make x by summing up some number of 11,111,1111,11111,…? (You can use any number among them any number of times). For instance, 33=11+11+11 144=111+11+11+11
177 0
Codeforces Round #723 (Div. 2)B. I Hate 1111