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;
}
标签:24,周赛,题目,int,题解,cin,que,x2,y2 来源: https://www.cnblogs.com/quanjun/p/16169322.html