暴力枚举+动态规划+模拟+数学
有两种情况:①+2 +0 ②+1 +1 ,但不管怎么样比赛次数一定是 +2 ,所以比赛次数总和一定是偶数
p1+p2<=p3
输出 p1+p2
p1+p2>p3
输出 (p1+p2+p3)/2
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int p1, p2, p3;
cin >> p1 >> p2 >> p3;
int x = p1 + p2 + p3;
if (x % 2 == 1)
cout << "-1\n";
else
cout << min(x / 2, p1 + p2) << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
B. Cat, Fox and the Lonely Array
二分+状态压缩+数据结构+贪心+数学+双指针
拆位转换成 0 1,那这道题就转换成为了两个 1 之间的最大距离(因为只有最大才能满足所有的要求)
小注意:1 0 0 0 0 是 5
but 这道题的思路感觉自己还得再理一下,maybe 晚点还会进行补充,更加充足
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 10;
int a[N];
void solve()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
int ans = 1;
for (int bit = 0; bit < 20; bit++)
{
int l = -1, mx = 0;
for (int i = 0; i < n; i++)
{
if (a[i] >> bit & 1)
{
mx = max(mx, i - l - 1);
l = i;
}
}
mx = max(mx, n - l - 1);
if (mx == n)
continue;
ans = max(ans, mx + 1);
}
cout << ans << '\n';
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}