二货小易有一个W*H的网格盒子 JAVA

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int h = sc.nextInt();
        int[][] arr=new int[w][h];
        int count=0;
        for(int i=0;i<w;i++){
            for(int j=0;j<h;j++){
                if(arr[i][j]==0){
                    count++;
                    if((i+2)<w){
                        arr[i+2][j]=-1;
                    }
                    if((j+2<h)){
                        arr[i][j+2]=-1;
                    }
                }
            }
        }
        System.out.print(count);
    }

猜你喜欢

转载自blog.csdn.net/qq_42612582/article/details/121714890