5.2CF总结
我太差了,拖累了整个队伍,又掉分了,场场打,场场掉
A题
我又看错题目了,白wa
distinct都标粗了,如果后面有数,换一下就好了,没数就不行
我的写法烦,且最重要的是,写错了一个小细节
B题
A,B都是签到思维题,我B被卡sqrt,有精度的问题
吃一堑长一智!(嗯
C题
题目有没有看完整,保证每个数都不超过x,n个数,放入m堆,然后问相邻的堆差不超过x
贪心即可,我糊掉了(我太容易糊掉了,我这道题目,一开始糊里糊涂的码了一遍,然后又删掉了,我发现我第二次整理了一下码的和第一遍差不多
不 要 一 下 冲 动 就 把 代 码 全 删 了 \color{orange}不要一下冲动就把代码全删了 不要一下冲动就把代码全删了
发 现 题 目 少 读 了 , 一 定 要 重 新 理 一 下 思 路 , 再 码 \color{orange}发现题目少读了,一定要重新理一下思路,再码 发现题目少读了,一定要重新理一下思路,再码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 10;
const int INF = 1e9 + 7;
const int MOD = 998244353;
struct node {
ll num;
ll id;
bool operator<(const node x) const {
if (x.num != num)
return num < x.num;
return id < x.id;
}
} a[MAX];
multiset<node> ans;
int vis[MAX];
int main() {
int T;
scanf("%d", &T);
while (T--) {
ans.clear();
ll n, m, x;
scanf("%lld %lld %lld", &n, &m, &x);
for (int i = 1; i <= n; i++) {
ll x;
scanf("%lld", &x);
a[i].num = x;
a[i].id = i;
}
for (int i = 1; i <= m; i++) {
node x = {0, i};
ans.insert(x);
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
auto x = ans.begin();
node xx = {x->num, x->id};
ans.erase(x);
xx.num += a[i].num;
vis[a[i].id] = xx.id;
ans.insert(xx);
}
bool flag = 1;
vector<ll> aaa;
for (auto x: ans) {
aaa.push_back(x.num);
}
if(aaa.size() != m) {
flag = 0;
}
int len = aaa.size();
ll maxx = -1, minn = INF;
for (int i = 1; i < len; i++) {
maxx = max(maxx, aaa[i]);
minn = min(minn, aaa[i]);
}
if(maxx - minn > x) flag = 0;
if(flag == 0) {
printf("NO\n");
continue;
}
printf("YES\n");
for (int i = 1; i <= n; i++) {
printf("%d ", vis[i]);
}
printf("\n");
}
}
D题
我卡死了,我的实现能力太差了
还有 一 定 要 想 清 楚 再 码 ! ! ! \color{orange}一定要想清楚再码!!! 一定要想清楚再码!!!
题意
有n个袜子,l个左袜子,r个右袜子
将左右袜子互换(不变颜色)消耗1
将一个袜子颜色变化为任意值 消耗1
问最小的消耗
题解
用两个multiset存袜子,记着删指针,删值可能会多删
有相同的删掉,现存的两个集合都没有相同的
如果集合大小相同,答案就是集合大小
如果不是,大的集合有重复颜色的话,把一个袜子放到小的集合里,ans++,
直到两个集合大小相同,ans += 剩下的集合消息
如果两个集合大小不同,就先匀成两个大小相同(+ (maxx - minn) / 2),再加上集合大小((maxx - minn) / 2 + minn)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e5 + 10;
const int INF = 1e9 + 7;
const int MOD = 998244353;
multiset<int> L;
multiset<int> R;
int a[MAX];
int b[MAX];
int main() {
int T;
scanf("%d", &T);
while (T--) {
L.clear();
R.clear();
int n, l, rr;
scanf("%d%d%d", &n, &l, &rr);
memset(a, 0, sizeof (int) * (l + 10));
memset(b, 0, sizeof (int) * (rr + 10));
for(int i = 1; i <= l; i++) {
int x;
scanf("%d", &x);
if (i <= l) L.insert(x);
}
for(int i = 1; i <= rr; i++) {
int x;
scanf("%d", &x);
auto it = L.find(x);
if (it != L.end()) {
L.erase(it);
} else {
R.insert(x);
}
}
if(L.size() == R.size()) {
printf("%lld\n", (ll) L.size());
continue;
}
ll ans = 0;
if(L.size() > R.size()) {
swap(L, R);
}
int cnt = 1;
for(auto x:R) {
a[cnt++] = x;
}
for(int i = 2; i < cnt; i++) {
if(a[i] == a[i - 1]) {
ans++;
a[i] = -1;
a[i - 1] = -1;
if(R.size() - ans * 2 <= (ll)L.size()) {
break;
}
}
}
R.clear();
for(int i = 1; i < cnt; i++) {
if(a[i] != -1) {
R.insert(a[i]);
}
}
if(L.size() == R.size()) {
printf("%lld\n", (ll)L.size() + ans);
continue;
}
ll maxx = max((ll)L.size(), (ll)R.size());
ll minn = min((ll)L.size(), (ll)R.size());
ans = ans + (maxx - minn) / 2;
ans = ans + (maxx - minn) / 2 + minn;
printf("%lld\n", ans);
}
}