Codeforces Round 945 (Div. 2) A - D题_哔哩哔哩_bilibili
讲解都在视频里哦
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
int p1, p2, p3;
cin >> p1 >> p2 >> p3;
vector<int> a({p1, p2, p3});
if ((p1 + p2 + p3) % 2 != 0)
cout << -1 << endl;
else
{
int cnt = 0;
while ((a[0] != 0 || a[1] != 0) && a[2] != 0)
{
a[2]--, a[1]--, cnt++;
sort(a.begin(), a.end());
}
cout << cnt << endl;
}
}
return 0;
}
B - Cat, Fox and the Lonely Array
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
vector<int> a(n);
for (auto& i : a)
cin >> i;
int finalAns = 1;
for (int i = 0; i <= 20; i++)
{
int cnt = 0, flag = 0;
int ans = 1;
for (auto j : a)
{
int dig = (j >> i) % 2;
if (dig == 0)
cnt++;
else
ans = max(ans, cnt + 1), cnt = 0, flag = 1;
}
if (cnt && flag)
ans = max(ans, cnt + 1);
finalAns = max(finalAns, ans);
}
cout << finalAns << endl;
}
cin.get();
cin.get();
return 0;
}
C - Cat, Fox and Double Maximum
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
int n, dig, cnt = 0;
cin >> n;
vector<int> a(n);
set<int> notChosen, chosen;
queue<int> allocation;
bool flag = true;
for (int i = 0; i < n; i++)
{
cin >> dig;
a[i] = dig;
allocation.push(n - i);
if (dig == 1 && i % 2 != 0 && i != n - 1)
flag = false;
}
if (flag)
for (int i = 0; i < n; i++)
if (i % 2 != 0 && i != n - 1)
chosen.insert(a[i]);
else
notChosen.insert(a[i]);
else
for (int i = 0; i < n; i++)
if (i % 2 == 0 && i != 0)
chosen.insert(a[i]);
else
notChosen.insert(a[i]);
map<int, int> M;
for (auto i : chosen)
M[i] = allocation.front(), allocation.pop();
for (auto i : notChosen)
M[i] = allocation.front(), allocation.pop();
for (auto i : a)
cout << M[i] << ' ';
cout << endl;
}
return 0;
}
D - Cat, Fox and Maximum Array Split
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
int n, k, dig, maxNum;
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
cout << "? " << 1 << ' ' << i * n << endl;
cin >> dig;
if (dig == n)
maxNum = i;
}
int m = -1;
for (int i = 1; i <= n / k; i++)
{
int l = 1, time = k;
while (l <= n && time--)
{
cout << "? " << l << ' ' << i * maxNum << endl;
cin >> dig;
if (dig == n + 1)
break;
l = dig + 1;
}
if (l == n + 1 && time == 0)
{
m = maxNum * i;
break;
}
}
cout << "! " << m << endl;
cin >> dig;
}
return 0;
}