[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;
}
相关推荐
木井巳9 分钟前
【BFS/DFS 解决 FloodFill 算法】太平洋大西洋水流问题
java·算法·leetcode·深度优先·广度优先·宽度优先·推荐算法
心抵鹊28 分钟前
归并排序之翻转对(hard)
数据结构·算法
白山编程大哥30 分钟前
Java 集合算法:从排序、查找到底层原理的实战指南
java·python·算法
_Twink1e41 分钟前
openJiuwen 实训营 Day 1 · WorkSwarm 入门教程
开发语言·c++·openjiuwen
shehuiyuelaiyuehao1 小时前
算法34,位运算符操作,总结
算法
Navigator_Z1 小时前
LeetCode //C - 1224. Maximum Equal Frequency
c语言·算法·leetcode
dong_junshuai2 小时前
每天一个开源项目#87 fmt:24.5K Stars 的 C++ 格式化核心
c++·开源·github
Navigator_Z2 小时前
LeetCode //C++ - 1226. The Dining Philosophers
c语言·算法·leetcode
FOORIR2 小时前
3D视觉+AI客流系统怎么做:从Sensor Pipeline到数据事件引擎
算法
雪的季节2 小时前
Multisim14.0的详细中文安装步骤【附安装包】
c++