# Codeforces Round #717 (Div. 2) 个人题解 Ａ～C （A思維，B位運算，C背包DP）

## 1516A. Tit for Tat

### 題意：

• 每次操作都選定兩個數（如果 $1 \le a_i$ ），使第一個數 - $1$ ，另一個數 + $1$

### 思路：

void solve() {
int n, k;
cin >> n >> k;
int a[n + 1];
for (int i = 1; i <= n; ++i) cin >> a[i];
int i = 1, j = n;
while (true) {
if (i == j || k == 0) break;
if (a[i] >= 1) a[i] -= 1, a[j] += 1, k--;
else
i++;
}
for (int i = 1; i <= n; ++i) cout << a[i] << " ";
cout << "\n";
}


## 1516B. AGAGA XOOORRR

### 思路：

void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int &x : a) cin >> x;
int s = 0;
for (int x : a) s ^= x;
if (s == 0) {
cout << "YES\n";
return;
}
int t = 0, cnt = 0;
for (int i = 0; i < n; ++i) {
t ^= a[i];
if (t == s) cnt++, t = 0;
}
if (cnt > 2 && t == 0) cout << "YES\n";
else
cout << "NO\n";
}


void solve() {
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1, x; i <= n; ++i) {
cin >> x;
a[i] = a[i - 1] ^ x;
}
bool f = !a[n];
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
f |= (a[i] == (a[j] ^ a[i]) && a[i] == (a[n] ^ a[j]));
cout << (f ? "YES\n" : "NO\n");
}


## 1516C. Baby Ehab Partitions Again

### 思路：

int dp[200010];
void solve() {
int n;
cin >> n;
vector<int> a(n + 1);
int d = 0;
for (int i = 1; i <= n; ++i) cin >> a[i], d = __gcd(d, a[i]);
for (int i = 1; i <= n; ++i) a[i] /= d;
dp[0] = 1;
int S = 0, id = 0;
for (int i = 1; i <= n; ++i) {
S += a[i];
if (a[i] & 1) id = i;
for (int j = S; j >= a[i]; j--) dp[j] |= dp[j - a[i]];
}
if (S & 1 || dp[S / 2] == 0) cout << "0";
else
cout << "1\n"
<< id;
}

posted @ 2021-04-22 19:22  RioTian  阅读(38)  评论(0编辑  收藏