寻宝!大冒险!ccf202206-02 模拟

题目链接: oj

寻宝!大冒险!

解题思路

题目

  1. 注意到全部数据中,L非常大,所以不能把绿化图直接存成矩阵。因为藏宝图左下角一定是1,所以我们可以把树的位置存在数组中,再遍历数组进行检验。
  2. 绿化图最右上角有一些元素因为剩余空间不够,所以必然不可能够成藏宝图的样子。
  3. 可以用class代替struct来实现运算符重载。

AC代码

/*
ccfcsp认证的第二题近几次难度有所增加,不再是简单模拟就可以得满分。
简单模拟会因为超时或者超空间等限制最多只能拿70分。
另外30分,限制难度也是越来越大。
比较青睐的考点:差分+前缀和 、 二维前缀和。
*/

#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;
class point
{

public:
    int x, y;
    bool operator==(point a)
    {
        return this->x == a.x && this->y == a.y;
    }
};
vector<point> v, cbt;

int main()
{
    int n, l, s;
    scanf("%d%d%d", &n, &l, &s);

    for (int i = 0; i < n; i++)
    {
        point buf;
        scanf("%d%d", &buf.x, &buf.y);
        v.push_back(buf);
    }
    int array[s + 1][s + 1];
    for (int i = s; i >= 0; i--)
    {
        for (int j = 0; j <= s; j++)
            scanf("%d", &array[i][j]);
    }
    int count = 0;
    for (vector<point>::const_iterator a = v.begin(); a != v.end(); a++)
    {
        point buf = *a;
        int flag = 1;
        for (int i = 0; i <= s; i++)
        {
            for (int j = 0; j <= s; j++)
            {
                point b;
                b.x = buf.x + i;
                b.y = buf.y + j;
                vector<point>::const_iterator it = find(v.begin(), v.end(), b);

                if ((array[i][j] == 1 && it == v.end()) || (array[i][j] == 0 && it != v.end())||b.x>l||b.y>l)
                {
                    flag = 0;
                    i = s;
                    j = s;
                }
            }
        }

        if (flag)
        {
            count++;
        }
    }
    printf("%d", count);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ccf202206-2是CCF(中国计算机学会)的2022年6月份的考试中的第2道题目。根据引用,这道题目是关于在大地图上寻找与小地图匹配的次数。大地图的数据范围很大,所以不能用二维数组进行存储整张地图,而是使用了vector<pair<int, int>>来存储大地图上给出的n个1的坐标。同时,小地图也进行了存储。引用是这道题目的一个参考代码,其中包含了读入数据、进行匹配计数的过程。我们可以根据这段代码理解题目的具体要求和实现方式。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [寻宝大冒险!CSP202206-2](https://blog.csdn.net/m0_57518208/article/details/125336982)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [CCF部分第四题解答](https://download.csdn.net/download/qq_29187357/9697906)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [202206-2 CCF 寻宝大冒险! (简单模拟 满分题解)](https://blog.csdn.net/qq_51800570/article/details/126673741)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值