[2023年12月17日]第15届蓝桥杯青少组stema选拔赛C++中高级(第二子卷、编程题(3))

参考程序:

cpp 复制代码
#include <iostream>
#include <set>
using namespace std;

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;

    set<int> filledRows, filledCols;

    // 读取被填色的行号
    for (int i = 0; i < x; i++) {
        int row;
        cin >> row;
        filledRows.insert(row);  // 将填色的行添加到集合中
    }

    // 读取被填色的列号
    for (int i = 0; i < y; i++) {
        int col;
        cin >> col;
        filledCols.insert(col);  // 将填色的列添加到集合中
    }

    // 计算未填色的行和列的数量
    int unfilledRows = n - filledRows.size();  // 未填色的行数
    int unfilledCols = m - filledCols.size();  // 未填色的列数

    // 未填色的小方格数量
    int unfilledSquares = unfilledRows * unfilledCols;

    cout << unfilledSquares << endl;  // 输出结果
    return 0;
}
相关推荐
哥不想学算法2 小时前
【C++】字符串字面量拼接
开发语言·c++
海石2 小时前
1500分的题目,确实有实力,不过还是我略胜一筹
算法·leetcode
海石2 小时前
【记忆化搜索】条条大路通AC,走好适合你的那一条,走到后再考虑走得快
算法·leetcode
Jerry4 小时前
LeetCode 151. 反转字符串中的单词
算法
a1117766 小时前
LM 算法迭代过程动画演示(SLAM)
算法
头茬韭菜6 小时前
Context 的生死抉择:四层压缩、截断算法与 Session Memory
算法·ai
Jerry7 小时前
LeetCode 541. 反转字符串 II
算法
Jerry7 小时前
LeetCode 344. 反转字符串
算法
cookies_s_s7 小时前
C++ 字符串动态创建对象 -- 工厂模式、自动注册、模板递归动态调用
服务器·开发语言·c++
搞科研的小刘选手7 小时前
【香港大学主办&IEEE出版】第六届计算机视觉、应用与算法国际学术会议(CVAA 2026)
算法·计算机视觉·应用·学术会议