A. Boboniu Likes to Color Balls

题意:

总共四个颜色,可以进行的操作是,前三个一人拿一个放到第四个,就相当于前三个都减一,第四个 Codeforces Round #664 (Div. 2)_按位与。然后得到的四个数,每个数对应一种字符的个数,问这些字符是否能构成回文串。

构成回文串的情况可以是

  • 个数为偶数的有四个,
  • 或者个数为偶数的有三个为奇数的有一个。
  • 还有就是全部都为奇数,然后经过一次操作前三个颜色都变成了偶数,最后一个颜色也变成了偶数,
  • 然后就是三个奇数的情况,假设前三个里面俩奇数一个偶数,最后那个是奇数,通过一次操作可以把前三个变成俩偶数一个奇数,最后那个变成偶数,假如前三个都是奇数,一次操作,前三个变成偶数最后的变成奇数。

AC代码:

const int N = 2e5 + 50;
int n, m;
int a[N];
int main()
{

int t;
sd(t);
while (t--)
{
int x = 0, y = 0;
rep(i, 1, 4)
{
cin >> a[i];
if (a[i] % 2)
y++;
else
x++;
}
if (x == 4 || x == 3 || ((y == 4 || y == 3) && (a[1] && a[2] && a[3])))
puts("Yes");
else
puts("No");
}
return 0;
}

B. Boboniu Plays Chess

题意:

给你 Codeforces Round #664 (Div. 2)_回文串_02的象棋,再给定一个初始点 Codeforces Round #664 (Div. 2)_按位与_03

Codeforces Round #664 (Div. 2)_回文串_04

AC代码:

const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int t;
int n, m;
int xx, yy;
int main()
{
sdd(n, m);
sdd(xx, yy);
per(i, yy, 1)
pdd(xx, i);
rep(i, yy + 1, m)
pdd(xx, i);
int cnt = 0;
rep(i, xx + 1, n)
{
if (cnt & 1)
{
rep(j, 1, m)
pdd(i, j);
}
else
{
per(j, m, 1)
pdd(i, j);
}
cnt++;
}
per(i, xx - 1, 1)
{
if (cnt & 1)
{
rep(j, 1, m)
pdd(i, j);
}
else
{
per(j, m, 1)
pdd(i, j);
}
cnt++;
}
return 0;
}

C. Boboniu and Bit Operations

题意:

给出了两个非负整数序列 Codeforces Round #664 (Div. 2)_回文串_05Codeforces Round #664 (Div. 2)_ci_06。对于每个 Codeforces Round #664 (Div. 2)_回文串_07,要求您选择一个 Codeforces Round #664 (Div. 2)_ci_08,并让 Codeforces Round #664 (Div. 2)_按位与_09,其中 Codeforces Round #664 (Div. 2)_回文串_10 表示按位与运算。请注意,您可以为不同的i选择相同的 Codeforces Round #664 (Div. 2)_ci_11。找到最小可能的 Codeforces Round #664 (Div. 2)_回文串_12,其中 Codeforces Round #664 (Div. 2)_回文串_13

Codeforces Round #664 (Div. 2)_按位与_14Codeforces Round #664 (Div. 2)_按位与_15匹配的所有可能都记录下来,枚举全部情况。

AC代码:

const int N = 2e2 + 50;
int n, m;
int a[N], b[N], bas[N][1027], vis[N][1027];
int len;

int main()
{

int t;
sdd(n, m);
rep(i, 1, n)
sd(a[i]);
rep(j, 1, m)
sd(b[j]);
rep(i, 1, n)
{
rep(j, 1, m)
{
bas[i][a[i] & b[j]] = 1;
}
}
len = 1 << 9;
vis[0][0] = 1;
rep(i, 1, n)
{
rep(j, 0, len)
{
if (!bas[i][j])
continue;
rep(k, 0, len - 1)
{
if (!vis[i - 1][k])
continue;
vis[i][k | j] = 1;
}
}
}
rep(i, 0, len - 1)
{
if (vis[n][i])
{
pd(i);
break;
}
}
return 0;
}

D. Boboniu Chats with Du

题意:

给出一个序列,拿大于 Codeforces Round #664 (Div. 2)_回文串_16 的接下来 Codeforces Round #664 (Div. 2)_回文串_17 天就不能拿了,拿小于 Codeforces Round #664 (Div. 2)_回文串_16

把大于 Codeforces Round #664 (Div. 2)_回文串_16 和小于 Codeforces Round #664 (Div. 2)_回文串_16 的分组,选 Codeforces Round #664 (Div. 2)_回文串_21个大于 Codeforces Round #664 (Div. 2)_回文串_16 的,肯定拿 Codeforces Round #664 (Div. 2)_回文串_21个快乐因子最大的,其中有一个在第 Codeforces Round #664 (Div. 2)_按位与_24 天放,只需要消耗 Codeforces Round #664 (Div. 2)_按位与_25天,所以此时消耗了 Codeforces Round #664 (Div. 2)_按位与_26 天。对于选取 Codeforces Round #664 (Div. 2)_回文串_21个大于 Codeforces Round #664 (Div. 2)_回文串_16 的先预处理出来需要几天,然后枚举选取小于 Codeforces Round #664 (Div. 2)_回文串_16

AC代码:

const int N = 2e5 + 50;
int n, d, m;
ll da[N], xiao[N];
ll sum[N], sumb[N];
int cnt1, cnt2, pos;
ll ans;

bool cmp(int a, int b)
{
return a > b;
}

int main()
{
sddd(n, d, m);
cnt1 = 0, cnt2 = 0;
rep(i, 1, n)
{
ll x;
sld(x);
if (x > m)
da[++cnt1] = x;
else
xiao[++cnt2] = x;
}
sort(da + 1, da + 1 + cnt1, cmp);
sort(xiao + 1, xiao + 1 + cnt2, cmp);
pos = 0;
rep(i, 1, n)
{
sum[i] = sum[i - 1];
if ((i % (d + 1)) == 1 && pos + 1 <= cnt1)
sum[i] += da[++pos];
}
rep(i, 1, cnt2)
sumb[i] = sumb[i - 1] + xiao[i];
ans = 0;
rep(i, 0, cnt2)
ans = max(ans, sumb[i] + sum[n - i]);
pld(ans);
return 0;
}