Codeforces Round #768 (Div. 2) A ~ C
Posted Ja_King_ZH
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #768 (Div. 2) A ~ C相关的知识,希望对你有一定的参考价值。
https://codeforces.com/contest/1631/problem/A
题意:给定两个数组,可以选择任意下标i,交换ai和bi,使得a数组最大值 * b数组最大值最小。
题解:将ai > bi 的移动到a数组,小于的放在b数组
const int N = 110;
int a[N], b[N];
int main()
int t;
cin >> t;
while (t--)
int n;
cin >> n;
int m1 = 0, m2 = 0;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
for (int i = 0; i < n; i++)
if (a[i] < b[i]) swap(a[i], b[i]);
sort(a, a + n);
sort(b, b + n);
m1 = a[n - 1], m2 = b[n - 1];
cout << m1 * m2 << endl;
return 0;
https://codeforces.com/contest/1631/problem/B
题意:每次可以选定2k长度的数组,并将后k段复制到前k段去,问数组所有元素相同时的最小操作次数。
题解:贪心,每次从后找到最长的相同段,然后倍增,直到大于数组长度。
const int N = 2e5 + 10;
int a[N], b[N];
int main()
int t;
cin >> t;
while (t--)
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int l = 0;
for (int i = n - 1; i >= 0; i--)
if (a[i] == a[n - 1]) l++;
else break;
int ans = 0;
while (l < n)
l *= 2;
for (int i = n - l - 1; i >= 0; i--)
if (a[i] == a[n - 1])
l++;
else break;
ans++;
cout << ans << endl;
return 0;
https://codeforces.com/contest/1631/problem/C
题意:给定n和k,从0到n-1中构造n/2对,使得
其中,n为2的指数倍。k为0到n-1
题解:每次0和n-1配对,1和n-2,2和n-3…可以构造出0。对于0到n-1,由于n-1和k可以构造出k,原本和k配对的n-1-k和0配对任然为0。对于n-1,在配一个1和3即可。但需要特判4。
int main()
int t;
cin >> t;
while (t--)
int n, k;
cin >> n >> k;
if (n == 4)
if (k == 3) cout << -1 << endl;
else if (k == 0)
cout << 0 << ' ' << n - 1 << endl;
cout << n - 2 << ' ' << n - 3 << endl;
else
cout << n - 1 << ' ' << k << endl;
cout << 0 << ' ' << n - 1 - k << endl;
else if (k > 0 && k < n - 1)
cout << n - 1 << ' ' << k << endl;
cout << 0 << ' ' << n - 1 - k << endl;
for (int i = 1, j = n - 2; i < j; i++, j--)
if(i != k && j != k) cout << i << ' ' << j << endl;
else if (k == 0)
for (int i = 0, j = n - 1; i < j; i++, j--)
cout << i << ' ' << j << endl;
else
cout << n - 1 << ' ' << n - 2 << endl;
cout << 0 << ' ' << n - 3 << endl;
cout << 1 << ' ' << 3 << endl;
cout << 2 << ' ' << n - 4 << endl;
for (int i = 4, j = n - 5; i < j; i++, j--)
cout << i << ' ' << j << endl;
return 0;
以上是关于Codeforces Round #768 (Div. 2) A ~ C的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #768 (Div. 2) A ~ C
Codeforces Round #768 (Div. 2) A ~ C
Codeforces Round #768 (Div. 2) A ~ C
Codeforces Round #436 E. Fire(背包dp+输出路径)