[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;
}
相关推荐
Turbo正则几秒前
群论在AI中的应用概述
人工智能·算法·抽象代数
ysa0510304 分钟前
【并查集】判环
c++·笔记·算法
持力行15 分钟前
C/C++ 中的 char*:它标识数组吗?为什么能用下标访问?
c语言·c++
Jerry21 分钟前
KeetCode 44. 开发商购买土地
算法
Jerry1 小时前
KeetCode 58. 区间和
算法
Jerry2 小时前
LeetCode 209. 长度最小的子数组
算法
汉克老师2 小时前
GESP2026年6月认证C++六级( 第三部分编程题(2、满二叉树))精讲
c++·深度优先·树形dp·满二叉树·gesp六级·树形dfs
彦为君2 小时前
算法思维与经典智力题
java·前端·redis·算法
智能优化与强化学习2 小时前
Gym(Gymnasium)仿真环境详解(二):环境简介、入门算法、调参要点、核心挑战
算法·强化学习·gym·零基础入门·算法评估
mxwin2 小时前
Unity Shader exp 函数的算法与渲染应用
算法·unity·游戏引擎·shader