lightoj1010思维

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

3

8 8

3 7

4 10

Sample Output

Case 1: 32

Case 2: 11

Case 3: 20

注意考虑3种情况,n和m中一个为1全可以放,n和m中一个为2,各一个田字格放,其他情况全放黑色 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t;
int main()
{
    scanf("%d",&t);
    int w=0;
    while(t--)
    {w++;
        int n,m;
        scanf("%d%d",&n,&m);
        int ans;
        if(n>m)
            swap(n,m);
        if(n==1)
            ans=n*m;

else if(n==2)
        {

                ans=(m/4)*4;
            if(m%4==1)
            ans+=2;
        else if(m%4>=2)
            ans+=4;
        }
      else
      {
          ans=n*m;
          if(ans%2==0)
            ans/=2;
          else
            ans=ans/2+1;
      }
       printf("Case %d: %d\n",w,ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sdauguanweihong/article/details/88732313