P1789 【Mc生存】插火把---Java

题目背景

初一党应该都知道......
题目描述

话说有一天 linyorson 在“我的世界”开了一个 n×n(n≤100)n\times n(n\le 100)n×n(n≤100) 的方阵,现在他有 mmm 个火把和 kkk 个萤石,分别放在 (x1,y1)...(xm,ym)(x_1,y_1)...(x_m,y_m)(x1​,y1​)...(xm​,ym​)(o1,p1)...(ok,pk)(o_1,p_1)...(o_k,p_k)(o1​,p1​)...(ok​,pk​) 的位置,没有光或没放东西的地方会生成怪物。请问在这个方阵中有几个点会生成怪物?

P.S.火把的照亮范围是:

    ||||||
    ||||||
    |||火把|||
    ||||||
    ||||||

萤石:

    ||||||
    ||||||
    |||萤石|||
    ||||||
    ||||||

输入格式

输入共m+k+1行。

第一行为n,m,k。

第2到第m+1行分别是火把的位置xi yi。

第m+2到第m+k+1行分别是萤石的位置oi pi。

注:可能没有萤石,但一定有火把。

所有数据保证在int范围内。
输出格式

有几个点会生出怪物。
输入输出样例
输入 #1

5 1 0
3 3

输出 #1

12
import java.util.Scanner;

public class P1789 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int[][] arr = new int[n + 3][n + 3];
        if (n == 2) {
            System.out.print("0");
        } else {
            for (int i = 1; i <= m; i++) {
                int x = sc.nextInt();
                int y = sc.nextInt();
                x = x + 2;
                y = y + 2;
                for (int j = x - 2; j < x + 1; j++) {
                    for (int l = y - 2; l < y + 1; l++) {
                        arr[j][l] = 1;
                        arr[x - 3][y - 1] = 1;
                        arr[x + 1][y - 1] = 1;
                        arr[x - 1][y - 3] = 1;
                        arr[x - 1][y + 1] = 1;
                    }
                }
            }
            for (int i = 1; i <= k; i++) {
                int x = sc.nextInt();
                int y = sc.nextInt();
                x = x + 2;
                y = y + 2;
                for (int j = x - 3; j <= x + 1; j++) {
                    for (int l = y - 3; l <= y + 1; l++) {
                        arr[j][l] = 1;
                    }
                }
            }
            int count = 0;
            for (int i = 2; i < n + 2; i++) {
                for (int j = 2; j < n + 2; j++) {
                    if (arr[i][j] == 0) {
                        count++;
                    }
                    //System.out.print(arr[i][j] + " ");
                }
                //System.out.println();
            }
            System.out.print(count);
        }
    }
}

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值