2024 ccfcsp认证打卡 2022 06 02 寻宝!大冒险!

在这里插入图片描述
在这里插入图片描述

import java.util.Scanner;

class Main {
    static class Point {
        int x, y;
        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();  // 树木的数量
        int l = sc.nextInt();  // 地图的大小
        int s = sc.nextInt();  // 藏宝图的大小

        Point[] tree = new Point[n];  // 存储树木的坐标
        for (int i = 0; i < n; ++i) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            tree[i] = new Point(x, y);
        }

        int[][] pic = new int[s + 1][s + 1];  // 藏宝图
        for (int i = s; i >= 0; --i) {
            for (int j = 0; j <= s; ++j) {
                pic[i][j] = sc.nextInt();
            }
        }

        int count = 0;  // 符合条件的树木数量
        for (int i = 0; i < n; ++i) {
            if (l - tree[i].x < s || l - tree[i].y < s) {
                continue;  // 越界跳过
            }
            int[][] temp = new int[s + 1][s + 1];
            int sx = tree[i].x;
            int sy = tree[i].y;

            // 初始化临时数组
            for (int j = 0; j <= s; ++j) {
                for (int k = 0; k <= s; ++k) {
                    temp[j][k] = 0;
                }
            }

            // 在临时数组中标记树木位置
            for (int j = 0; j < n; ++j) {
                if (tree[j].x - sx < 0 || tree[j].x - sx > s || tree[j].y - sy < 0 || tree[j].y - sy > s) {
                    continue;
                }
                temp[tree[j].x - sx][tree[j].y - sy] = 1;
            }

            int flag = 0;
            // 检查临时数组与藏宝图是否匹配
            for (int j = 0; j <= s; ++j) {
                for (int k = 0; k <= s; ++k) {
                    if (temp[j][k] != pic[j][k]) {
                        flag = 1;
                        break;
                    }
                }
                if (flag == 1) {
                    break;
                }
            }
            if (flag == 0) {
                count++;
            }
        }
        System.out.println(count);  // 输出符合条件的树木数量
        sc.close();
    }
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值