蓝桥杯模拟五 蒜头君下棋

蒜头君喜欢下棋。最近它迷上了国际象棋。国际象棋的棋盘可以被当做一个 8\times 88×8 的矩阵,棋子被放在格子里面(不是和中国象棋一样放在线上)。

蒜头君特别喜欢国际象棋里面的马,马的移动规则是这样的:横着走两步之后竖着走一步,或者横着走一步之后竖着走两步。例如,一匹马在 (3,3)(3,3) 的位置,则它可以到达的地方有 (1,2)(1,2),(2,1)(2,1),(1,4)(1,4),(4,1)(4,1),(5,2)(5,2),(2,5)(2,5),(5,4)(5,4),(4,5)(4,5) 八个地方。蒜头君想要把整个棋盘都放上马,并且让这些马不能相互攻击(即任何一匹马不能走一步之后就到达另一匹马的位置)。蒜头君当然知道在 8 \times 88×8 的棋盘上怎么放马,但如果棋盘变为 n \times mn×m 的,蒜头君就不懂了。他希望你来帮忙他计算一下究竟能放多少匹马。

输入格式

共一行,两个整数nn和mm(1 \leq n , m \leq 10001n,m1000),代表棋盘一共有 nn 行 mm列。

输出格式

输出一个整数,代表棋盘上最多能放的马的数量。

样例输入1

2 4

样例输出1

4

样例输入2

3 4

样例输出2

6

  1. 对于题目给出的n,m,让a是m,n中的较小者,让b是m,n中的较大者。  
  2. 如果n为1,则按图1排放,即图中最上方的图。  
  3. 如果n为2,则按图2排放。即图中中间的图。  
  4. 如果n比2大,则按图3排方。即图中最下方的图。 

参考博客

https://blog.csdn.net/wyxeainn/article/details/79695436

 

#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#define maxn 1010
#define debug(a) cout << #a << " : " << a << endl
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    if( n > m ) {
        swap( n, m );
    }
    if( n == 1 ) {
        cout << m << endl;
    } else if( n == 2 ) {
        if( m % 4 == 3 ) {
            cout << ( m / 4 ) * 4 + 4 << endl;
        } else {
            cout << ( m / 4 ) * 4 + ( m % 4 ) * 2 << endl;
        }
    } else {
        cout << ( n * m + 1 ) / 2 << endl;
    }
    return 0;
}

 


 


posted on 2018-03-28 16:45  九月旧约  阅读(290)  评论(0编辑  收藏  举报

导航