【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!

相关文章
|
1月前
|
人工智能 测试技术 BI
Codeforces Round 942 (Div. 2)
Codeforces Round 942 (Div. 2)
|
1月前
|
机器学习/深度学习 人工智能 测试技术
Codeforces Round 960 (Div. 2)
Codeforces Round 960 (Div. 2)
|
人工智能
Codeforces Round #786 (Div. 3)(A-D)
Codeforces Round #786 (Div. 3)(A-D)
72 0
【CodeForces】Codeforces Round 857 (Div. 2) B
【CodeForces】Codeforces Round 857 (Div. 2) B
130 0
Equidistant Vertices-树型dp-Codeforces Round #734 (Div. 3)
Description A tree is an undirected connected graph without cycles. You are given a tree of n vertices. Find the number of ways to choose exactly k vertices in this tree (i. e. a k-element subset of vertices) so that all pairwise distances between the selected vertices are equal (in other words,
139 0
|
人工智能
Codeforces Round #443 (Div. 2) A B C
A. Borya’s Diagnosis time limit per test2 seconds memory limit per test256 megabytes inputsta...
1023 0