2021-12-15【Codeforces Round #760 (Div
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn=1e6+5;
void solve(){
int n;
cin >> n;
string a, b;
cin >> a;
string cnt=a;
for (int i = 1; i < n - 2;i++){
cin>>b;
if(a[1]==b[0])
cnt += b.substr(1);
else
cnt += b;
a = b;
}
while(cnt.size()<n)
cnt += "a";
cout << cnt << endl;
}
int main(){
ios::sync_with_stdio(0);
int t;
cin >> t ;
while(t--){
solve();
}
return 0;
}
[](()C. Paint the Array
=====================================================================================
[](()题目描述
![](https://static001.geekbang.org/infoq/ec/ec27b8cc17d337d433387e26d93af23a.png)
[](()思路:求奇数位和偶数位所有数的最大公因数 gcd(),用奇数 gcd()检测偶数位的所有数,用偶数 gcd()检测所有奇数位的数,如果不能被整除,则该 gcd()为一个答案,否则为“0”。
[](h 《一线大厂 Java 面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 ttps://blog.csdn.net/eternity_memory/article/details/121943327)code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn=1e6+5;
ll gcd(ll a, ll b){
return a % b == 0 ? b : gcd(b, a % b);
}
int n;
bool check(int c,ll b,ll a[]){
for (int i = c; i < n;i+=2){
if(a[i]%b==0){
return 0;
}
}
return 1;
}
void solve()
{
cin>>n;
ll a1, b;
ll a[105] = {0};
for (int i = 0; i < n;i++){
cin >> a[i];
}
if (n >= 4){
a1 = gcd(a[0], a[2]);
b = gcd(a[1], a[3]);
}else if(n==3){
a1 = gcd(a[0], a[2]);
b = a[1];
}else{
a1 = a[0];
b = a[1];
}
for (int i = 4;i<n;i+=2){
a1 = gcd(a1, a[i]);
if(i+1<n)
b = gcd(b, a[i + 1]);
}
if(check(0,b,a)){
cout << b << endl;
}else if(check(1,a1,a)){
cout << a1 << endl;
}else
cout << 0 << endl;
}
int main(){
ios::sync_with_stdio(0);
int t;
cin >> t ;
while(t--){
solve();
}
return 0;
}
[](()D. Array and Operations
==========================================================================================
[](()题目描述
![](https://static001.geekbang.org/infoq/00/0054a5e07ba41aeda1c8dad4327217d4.png)
[](()思路:~一点点的~ 思维,数组排序后,对后 2*k 个树进行操作,由题意可知,题目中求最小的和,而分解到每一步高斯的结果要么为 1,要么为 0,所以用贪心的思想,使其尽可能为 0。
[](()code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn=1e6+5;
int a[maxn],b[maxn];
void solve(){
int n, k;
cin >> n >> k;
for (int i = 0;i<n;i++){
cin >> a[i];
评论