| Time Limit: 1 second(s) | Memory Limit: 32 MB |
Given an m x n chessboard where you want to place chess knights. You have to find the number of maximum knights that can be placed in the chessboard such that no two knights attack each other.
Those who are not familiar with chess knights, note that a chess knight can attack 8 positions in the board as shown in the picture below.

Input
Input starts with an integer T (≤ 41000), denoting the number of test cases.
Each case contains two integers m, n (1 ≤ m, n ≤ 200). Here m and n corresponds to the number of rows and the number of columns of the board respectively.
Output
For each case, print the case number and maximum number of knights that can be placed in the board considering the above restrictions.
Sample Input | Output for Sample Input |
| 3 8 8 3 7 4 10 | Case 1: 32 Case 2: 11 Case 3: 20 |
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int t,n,m;
int k=1;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
printf("Case %d: ",k++);
if(n>m)
{
int temp=n;n=m;m=temp;
}
if(n==1)
printf("%d\n",m);
else if(n==2)
{
if(m%4==3)
printf("%d\n",(m/4)*4+4);
else
printf("%d\n",(m/4)*4+(m%4)*2);
}
else
printf("%d\n",(n*m+1)/2);
}
return 0;
}

本文探讨了一个关于在mxn大小的棋盘上放置骑士的问题,目标是找出最多能放置多少个骑士使得它们不会互相攻击。文章给出了具体的输入输出示例,并提供了一段C++代码实现解决方案。

250

被折叠的 条评论
为什么被折叠?



