NYOJ题目893十字架

------------------------------------

这道题有坑,题目描述含糊不清,出题人水平不太行啊....

组成十字架的必须是1,并且是5个,不算大的十字架之类的。

AC代码如下:

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4 
 5     public static void main(String[] args) {
 6         
 7         Scanner sc=new Scanner(System.in);
 8         
 9         int times=sc.nextInt();
10         while(times-->0){
11             matrix=new int[w][w];
12             for(int i=0;i<w;i++){
13                 for(int j=0;j<w;j++){
14                     matrix[i][j]=sc.nextInt();
15                 }
16             }
17             
18             System.out.println(dfs());
19         }
20         
21     }
22     
23     private static int matrix[][],w=7;
24     
25     private static int dfs(){
26         int ans=0;
27         for(int i=1;i<w;i++){
28             for(int j=1;j<w;j++){
29                 if(isCross(i,j)) ans++;
30             }
31         }
32         return ans;
33     }
34     
35     private static boolean isCross(int x,int y){
36         if(x<1 || x>=w-1 || y<1 || y>=w-1) return false;
37         if(matrix[x][y]!=1) return false;
38         return 1==matrix[x-1][y] && 1==matrix[x+1][y] && 1==matrix[x][y-1] && 1==matrix[x][y+1];
39     }
40     
41 }

题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=893

原文地址:https://www.cnblogs.com/cc11001100/p/5862105.html