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

相关文章
|
7月前
Codeforces Round #192 (Div. 2) (329A)C.Purification
Codeforces Round #192 (Div. 2) (329A)C.Purification
22 0
|
7月前
Codeforces Round #192 (Div. 2) (330A) A. Cakeminator
如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕。
26 0
|
7月前
|
人工智能 算法 BI
Codeforces Round #179 (Div. 2)A、B、C、D
我们每次加进来的点相当于k,首先需要进行一个双重循环找到k点和所有点之间的最短路径;然后就以k点位判断节点更新之前的k-1个点,时间复杂度降到O(n^3),而暴力解法每次都要进行floyd,时间复杂度为O(n^4);相比之下前述解法考虑到了floyd算法的性质,更好了运用了算法的内质。
36 0
|
9月前
|
机器学习/深度学习 Go
codeforces round 885 (div. 2)
codeforces round 885 (div. 2)
63 0
【CodeForces】Codeforces Round 857 (Div. 2) B
【CodeForces】Codeforces Round 857 (Div. 2) B
87 0
Codeforces Round #442 (Div. 2) A B
A. Alex and broken contest time limit per test2 seconds memory limit per test256 megaby...
1059 0

热门文章

最新文章