[算法]Bobmer
2023-09-14 09:01:21 时间
package com.company; import com.sun.org.apache.bcel.internal.generic.AASTORE; import java.awt.*; import java.awt.event.ItemEvent; import java.util.*; import java.util.List; public class Main { static int N, S; static int[] R = new int[30]; static int[] C = new int[30]; static int[][] Zone = new int[50][50]; static int Answer; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int test_case = 1; test_case <= T; test_case++) { /* Read each test case from standard input. */ N = sc.nextInt(); S = sc.nextInt(); for(int i=0; i<N; i++) { for(int j=0; j<N; j++) { Zone[i][j] = 0; } } for(int i = 0; i < S; i++) { R[i] = sc.nextInt(); C[i] = sc.nextInt(); } ///////////////////////////////////////////////////////////////////////////////////////////// /* Implement your algorithm from this section. */ ///////////////////////////////////////////////////////////////////////////////////////////// for (int i = 0; i < S; i++) { calExplosionArea(R[i], C[i]); } Answer = 0; for(int i=0; i<N; i++) { for(int j=0; j<N; j++) { if (Zone[i][j] != 0 && Zone[i][j] > Answer) { Answer = Zone[i][j]; } } } // Print the answer to standard output(screen). System.out.println("#" + test_case + " " + Answer); }} private static void calExplosionArea(int X, int Y) { //Zone[X][Y]++; if (X-1 >= 0) { Zone[X-1][Y]++; if (Y-1 >= 0) { Zone[X-1][Y-1]++; } if (Y+1 <= N-1) { Zone[X][Y+1]++; Zone[X-1][Y+1]++; } } if ((X+1 <= N-1)) { Zone[X+1][Y]++; if (Y-1 >= 0) { Zone[X+1][Y-1]++; Zone[X][Y-1]++; } if (Y+1 <= N-1) { Zone[X+1][Y+1]++; } } } }
相关文章
- 激光SLAM算法学习(三)——3D激光SLAM
- 最短路径之Dijkstra(迪杰斯特拉)算法(无向图)
- 日拱算法:两个数组的交集(I、II)
- DP算法分类总结_算法总结
- 基础算法篇——归并排序
- 机器学习_knn算法_2
- 面部识别算法是如何工作的?
- [CVPR | 论文简读] 深度密度的无约束人脸聚类算法
- JavaScript刷LeetCode-贪心算法
- 字节跳动《算法中文手册》完整版 PDF 开放下载!
- Java 对称加密几种算法分别实现详解编程语言
- 多级队列调度算法(含实例分析)
- 从数据算法到人工智能,带你穿越重重迷雾 | AI科技评论周刊
- 从理论到实践,一文详解 AI 推荐系统的三大算法
- php下的权限算法的实现
- C#算法之关于大牛生小牛的问题