🚥🚥🚥
这道题的细节很妙(好像这就是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'; } }
注意:任何数都可以除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!