LightOJ - 1010 Knights in Chessboard

Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu

Status

Description

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

Source

Problem Setter: Jane Alam Jan

Status

 

题意: 棋盘上放旗子 , 原题 给了个图 , 说明了棋子会相互攻击情况,  求最多可以放多少棋子;

   观察可得, 棋子全放白的或全放黑的满足条件,

 两种特殊情况 ;

 n==1时全放上都可;

 n==2时先放满正方形的四个格,  然后空出四个格,  最后可能会出现空1, 2, 3,格情况 , 而空三格也是最多放2个 ; 得出代码--

#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
    int t;
    scanf("%d", &t);
    int Q=1; 
    while(t--)
    {
        int n, m;
        scanf("%d%d", &n, &m);
        if(n>m)
            swap(n, m);
        int x, y;
        x=n*m;
        x=x/2;
        y=n*m-x;
        y=max(x, y);
        if(n==1)
            x=m;
        if(n==2)
            x =2*(2*(m/4)+min(2, m%4));
        printf("Case %d: %d\n", Q++, max(x, y));  //行*2 == 两行;
    } 
    return 0;
}

 

   

   

转载于:https://www.cnblogs.com/soTired/p/5330431.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值