A

题意:

d取任意正整数,使得gcd(a+d,b+d)最大:

对于任意整数 ab(假设 ab)有:
gcd(a,b)=gcd(a,ba)

因此,将 a=x+db=y+d 代入:gcd(x+d,y+d)=gcd(x+d,(y+d)−(x+d))=gcd(x+d,yx)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <utility>
using namespace std;
typedef long long LL;
const int N = 1e5 +10;
int arr[N];

typedef pair<int, int> PA;
typedef pair<PA, int> PA2;
int n,m;
void solve() {
int minnum = 1e9,maxnum = -1;
int tmp,n;
cin >> n;
while(n--)
{
cin >> tmp;
minnum = min(minnum,tmp);
maxnum = max(maxnum,tmp);
}
cout << maxnum - minnum << endl;
}

int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
while(n--) {
solve();
}
}

B

题意:
操作:数字可以沿主对角线和副对角线移动,通过移动:判断能否将a字符串转化为全0。

可以推出,

对于a字符串奇数位置上的1,只能转化到b字符串偶数下标上。

对于a字符串偶数下标位置上的1,只能转化到b字符串奇数下标上。

同时由于字符串长度可能不为偶数,要分情况讨论:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <utility>
using namespace std;
typedef long long LL;
const int N = 1e5 +10;
int arr[N];

typedef pair<int, int> PA;
typedef pair<PA, int> PA2;
int n,m;
string a, b;

void solve() {
cin >> m;
cin >> a >> b;
bool flag = true;
int odda = 0, oddb = 0;
int evena = 0, evenb = 0;
for(int i = 0; i < m; i++)
{

if(flag)
{
if(a[i] == '1')
odda++;
if(b[i] == '1')
oddb++;
}
else
{
if(a[i] == '1')
evena++;
if(b[i] == '1')
evenb++;
}
flag = !flag;
}
//cout << odda << " " << oddb << " " << evena << " " << evenb << endl;
// cout << m/2 << endl;
if(m%2==0)
{
if(odda + evenb <= m/2 && oddb + evena <= m/2)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
else {
if(odda + evenb <= m/2 && oddb + evena <= m/2+1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}

}

int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
while(n--) {
solve();
}
}

C

题意:取一数a和数b,令a+b为奇数,求经过若干操作后,能取到的最大值

由于每次操作后,奇数的个数和偶数的个数,都不会改变。

  1. 若全为奇数和偶数,则无法操作,直接输出最大值

  2. 令偶数变成0,奇数变成1。可得到最大值的奇数值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <utility>
using namespace std;
typedef long long LL;
const int N = 1e5 +10;
int arr[N];

typedef pair<int, int> PA;
typedef pair<PA, int> PA2;
int n,m;

void solve() {

int odd = 0;
int even = 0;
int k ;
cin >> k;
long long cnt = 0;
int maxnum = -1;
for(int i = 0; i < k; i++)
{
int tmp;
cin >> tmp;
if(tmp % 2 == 0)
even++;
else
odd++;
cnt+=tmp;
maxnum = max(maxnum, tmp);
}
if(even == k || odd == k)
{
cout << maxnum << endl;
}
else {
cout << cnt-odd+1 << endl;
}


}

int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
while(n--) {
solve();
}
}

参考

Codeforces Round 1014 (Div. 2) A-E - 知乎