关键点,当坐标为i,j时 欧几里得距离只有i+2,j 和 i,j+2
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.println(count); } }