贪心:4个一组蛋糕方阵,相邻4个一组的空白方阵,交替摆放即可:
import java.util.*; public class Main { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int W = sc.nextInt(), H = sc.nextInt(); if(W <= 2 && H <= 2) { System.out.println(W*H); return; } if(W <= 2){ int temp = W; W = H; H = temp; } int r = 0, a = W/2, b = W%2; if(b == 1) a++; int len1 = a, len2 = a - 1; r += H/4*2*W; if(H%4 == 1) r += len1; if(H%4 == 2) r += 2*len1; if(H%4 == 3) r += len1 + W; System.out.println(r); } }