【CoreForces Round #102D】Help General

D.Help General
简化题意:一个N*M的棋盘上可以放下多少个中国象棋里的马 (也就是两个棋子的坐标差的平方不能等于5)
题解:

[当N或M有一个等于1时,结果为N*M ]

[当N或M有一个等于2时,每8个方块可以放4个马,剩下的模块最多可以放4个 ]

[其他情况时,结果为N*M/2向上取整 ]

#include <cstdio>  
using namespace std;  
int main(){  
    int N,M;  
	scanf("%d%d",&N,&M);  
	if(M==1||N==1)printf("%d
",N*M);  
	else{  
        if(N==2||M==2){  
            int a=N*M/2;  
			switch(a%4){  
                case 0:{  
                    printf("%d
",(a/2)*2);  
					return 0;  
				}  
                case 1:{  
                    printf("%d
",(a/2)*2+2);  
					return 0;  
				}  
                case 2:{  
                    printf("%d
",(a/2)*2+2);  
					return 0;  
				}  
                case 3:{  
                    printf("%d
",(a/2)*2+2);  
					return 0;  
				}  
            }  
        }  
        else{  
            printf("%d
",N*M/2+((N*M)%2+1)/2);  
		}  
    }  
    return 0;  
}
原文地址:https://www.cnblogs.com/Vagrant-ac/p/12149610.html