寻宝!大冒险!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
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值