AcWing 第24场周赛

4070. 异或

题目链接

4070. 异或 - AcWing题库

解题思路

记录最大值和最后值,然后异或

十分没有技术含量的题

代码

#include<iostream>
#include<algorithm>
using namespace std;

int a[15];

int main()
{
    int n;  cin >> n;
    for(int i=0 ; i<n ; i++)
        cin >> a[i];

    int b = a[n-1], c;
    sort(a, a+n);
    c = a[n-1];

    cout << (b^c);

    return 0;
}

4071. 国际象棋

题目链接

4071. 国际象棋 - AcWing题库

解题思路

由于只有8X8 的棋盘,所以可以“暴力”一点

用bool二维数组记录每个点可不可以放置,再遍历整个数组计算可行数量

代码

#include <iostream>
#include <cstring>
using namespace std;

typedef pair<int,int> PII;
PII p;

bool st[10][10];
char c[2], cc[2];
int dx[] = {1, 1, 2, 2,-1,-1,-2,-2};
int dy[] = {2,-2, 1,-1, 2,-2, 1,-1};
int tt;

PII ask(char tc[])
{
    int y = tc[1]-'0';
    if(tc[0]=='a')
        return {1, y};
    if(tc[0]=='b')
        return {2, y};
    if(tc[0]=='c')
        return {3, y};
    if(tc[0]=='d')
        return {4, y};
    if(tc[0]=='e')
        return {5, y};
    if(tc[0]=='f')
        return {6, y};
    if(tc[0]=='g')
        return {7, y};
    if(tc[0]=='h')
        return {8, y};
}

int main()
{
    cin >> c;
    p = ask(c);
    for(int i=1 ; i<=8 ; i++)
        st[p.first][i] = st[i][p.second] = true;
    for(int i=0 ; i<8 ; i++)
    {
        int tx = p.first+dx[i], ty = p.second+dy[i];
        if(tx<1 || tx>8 || ty<1 || ty>8) continue;
        st[tx][ty] = true;
    }

    cin >> cc;
    p = ask(cc);
    st[p.first][p.second] = true;
    for(int i=0 ; i<8 ; i++)
    {
        int tx = p.first+dx[i], ty = p.second+dy[i];
        if(tx<1 || tx>8 || ty<1 || ty>8) continue;
        st[tx][ty] = true;
    }

    int cnt = 0;
    for(int i=8 ; i>0 ; i--)
        for(int j=1 ; j<=8 ; j++)
            if(!st[i][j])
                cnt++;


    cout << cnt;

    return 0;
}

4072. 习题册

题目内容

某书店出售 nn 套习题册。

每套习题册可以用三个整数 pi,ai,bipi,ai,bi 来描述,表示该习题册的价格为 pipi,前半部分内容考察知识点 aiai,后半部分内容考察知识点 bibi。

已知,所有 pipi 各不相同,aiai 和 bibi 都是 1∼31∼3 的整数,且 aiai 和 bibi 可能相等。

有 mm 个学生前来购买习题册。

这 mm 个学生是一个接着一个来的,前一个学生走后,后一个学生才会到店。

每个学生都只想买 11 套习题册。

第 ii 个学生希望重点练习知识点 cici,所以在轮到第 ii 个学生进行选购时,他只会挑选包含知识点 cici 的习题册进行购买,如果这样的习题册不止一本,他就会挑选最便宜的那个购买,如果这样的习题册一本都没有,他就会放弃购买,直接走人。

请你计算,每个学生购买习题册花了多少钱。

输入格式

第一行包含整数 nn。

第二行包含 nn 个整数 p1,p2,…,pnp1,p2,…,pn。

第三行包含 nn 个整数 a1,a2,…,ana1,a2,…,an。

第四行包含 nn 个整数 b1,b2,…,bnb1,b2,…,bn。

第五行包含整数 mm。

第六行包含 mm 个整数 c1,c2,…,cmc1,c2,…,cm。

输出格式

共一行,输出 mm 个整数,第 ii 个整数表示第 ii 个学生购买习题册的花费,如果该学生什么也没买,则输出 −1−1。

数据范围

前三个测试点满足,1≤n,m≤10
所有测试点满足,1≤n,m≤2×10^5 1≤ai,bi,ci≤3,1≤pi≤10^9


解题思路

  • 数据范围:20万 所以用O(nlogn)的时间复杂度
  • 操作:取最小值,删最小值 所以用堆
  • 堆:分三个堆,分别表示第123个知识点

代码

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

#define x first
#define y second
typedef pair<int,int> PII;
const int M = 200010;

priority_queue <PII, vector<PII>, greater<PII> > h[3];
bool st[M];
int p[M];

int main()
{
    int n, m;
    cin >> n;
    for(int i=0 ; i<n ; i++)
        cin >> p[i];
    
    for(int j=0 ; j<2 ; j++)
        for(int i=0 ; i<n ; i++)
        {
            int a;
            cin >> a;
            h[a-1].push({p[i], i});
        }
    
    cin >> m;
    while(m--)
    {
        int c;
        cin >> c;
        c--;
        
        while(h[c].size() && st[h[c].top().y]) h[c].pop();
        if(h[c].empty())    cout << "-1 ";
        else
        {
            auto t = h[c].top();
            cout << t.x << " ";
            h[c].pop();
            st[t.y] = true;
        }
    }
    
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值