AcWing第24场周赛题解
A. 4070. 异或
题目链接:https://www.acwing.com/problem/content/4073/
题目大意:略。
解题思路:简单模拟。
示例程序:
#include <bits/stdc++.h>
using namespace std;
int n, a[11], res;
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
res = a[n-1];
sort(a, a+n);
res ^= a[n-1];
cout << res << endl;
return 0;
}
B. 4071. 国际象棋
题目链接:https://www.acwing.com/problem/content/4074/
题目大意:略。
解题思路:简单模拟,找不会攻击到的位置即可。
示例程序:
#include <bits/stdc++.h>
using namespace std;
char s1[3], s2[3];
int x1, Y1, x2, y2, cnt;
bool f1(int x, int y) {
return x == x1 || y == Y1;
}
bool f2(int x, int y, int x2, int y2) {
if (x == x2 && y == y2) return true;
int t1 = abs(x - x2), t2 = abs(y - y2);
return t1==1 && t2==2 || t1==2 && t2==1;
}
int main() {
cin >> s1 >> s2;
x1 = s1[0] - 'a' + 1;
Y1 = s1[1] - '0';
x2 = s2[0] - 'a' + 1;
y2 = s2[1] - '0';
for (int i = 1; i <= 8; i++)
for (int j = 1; j <= 8; j++)
if (!f1(i, j) && !f2(i, j, x1, Y1) && !f2(i, j, x2, y2))
cnt++;
cout << cnt << endl;
return 0;
}
C. 4072. 习题册
题目链接:https://www.acwing.com/problem/content/4075/
题目大意:略。
解题思路:模拟,贪心。(主要这场比赛我是在公交车上面做的,过了一个礼拜再回来看,只记得还算简单+用了优先队列,其他大家自己看代码吧)
示例程序:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
struct Book {
int p, id;
bool operator < (const Book& b) const {
return p > b.p;
}
} a[maxn];
bool vis[maxn];
priority_queue<Book> que[4];
int n, m, c;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
a[i].id = i;
cin >> a[i].p;
}
for (int i = 0; i < n; i++) {
cin >> c;
que[c].push({a[i].p, i});
}
for (int i = 0; i < n; i++) {
cin >> c;
que[c].push({a[i].p, i});
}
cin >> m;
while (m--) {
cin >> c;
while (!que[c].empty() && vis[que[c].top().id]) que[c].pop();
if (!que[c].empty()) {
Book u = que[c].top();
que[c].pop();
vis[u.id] = true;
cout << u.p << " ";
} else cout << -1 << " ";
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
2020-04-20 CF231C To Add or Not to Add 题解 双指针
2020-04-20 CF1251C Minimize The Integer 题解 双指针