ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

AcWing第24场周赛题解

2022-04-20 12:32:29  阅读:157  来源: 互联网

标签:24 周赛 题目 int 题解 cin que x2 y2


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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有