题解 AT5805 【Bishop】

· · 题解

在一个 n\times m 的棋盘上,一个象从左上角开始能走到的格子数为 \dfrac{n\times m+1}{2},但需要特判 n=1 或 m=1 的情况,因为这时象只能在原地不动。

#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
    re int t=0;
    re char v=getchar();
    while(v<'0')v=getchar();
    while(v>='0'){
        t=(t<<3)+(t<<1)+v-48;
        v=getchar();
    }
    return t;
}
long long n,m;
int main(){
    n=read();m=read();
    if(n>1&&m>1)
    printf("%lld",(n*m+1)/2);
    else puts("1");
}