# Codeforces Round #661(Div. 3)解题报告

## Codeforces Round #661(Div. 3)

### A. Remove Smallest

#### 题目大意

∣ a i − a j ∣ ≤ 1 |a_{i}-a_{j}|\leq 1 则可以删去 m i n ( a i , a j ) min(a_{i},a_{j}) ，问你能否将 a a 数组删至只剩一个元素

#### 解题思路

a a 数组进行排序，对于每两个相邻的元素判断差值是否大于1

#### AC代码

#include <bits/stdc++.h>
using namespace std;
int a[100];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
bool flag = true;
for (int i = 2; i <= n; ++i) {
if (a[i] - a[i - 1] > 1) {
flag = false;
break;
}
}
cout << (flag ? "YES" : "NO") << '\n';
}
return 0;
}


#### AC代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[110], b[110];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
ll Mina = LONG_MAX, Minb = LONG_MAX;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
Mina = min(Mina, a[i]);
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
Minb = min(Minb, b[i]);
}
ll res = 0;
for (int i = 1; i <= n; ++i) {
res += max(a[i] - Mina, b[i] - Minb);
}
cout << res << '\n';
}
return 0;
}


### C. Boats Competition

#### AC代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[110];
int solve(int x) {
int res = 0;
int l = 1, r = n;
while (true) {
if (l >= r) break;
if (a[r] + a[l] > x) --r;
else if (a[r] + a[l] < x) ++l;
else {
++res;
++l;
--r;
}
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
int nn = n * 2;
int res = 0;
for (int i = 1; i <= nn; ++i) {
res = max(res, solve(i));
}
cout << res << '\n';
}
return 0;
}


### 解题思路

#### AC代码

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
string s;
cin >> s;
vector<int> v[2];
int tot = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '0') {
if (v[1].empty()) a[i] = ++tot;
else {
a[i] = a[v[1].back()];
v[1].pop_back();
}
v[0].push_back(i);
}
else {
if (v[0].empty()) a[i] = ++tot;
else {
a[i] = a[v[0].back()];
v[0].pop_back();
}
v[1].push_back(i);
}
}
cout << tot << '\n';
for (int i = 0; i < n; ++i) cout << a[i] << " ";
cout << '\n';
}
return 0;
}

03-17

07-06 188
12-16 2654