您的位置:首页 > 其它

1010 - Knights in Chessboard(找规律)

2016-03-29 19:14 363 查看
http://www.lightoj.com/volume_showproblem.php?problem=1010

1010 - Knights in Chessboard





PDF (English)StatisticsForum
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 <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <string>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
const int SIZE=1e5+10;
const int maxn=500000;
int main()
{
int T;
scanf("%d",&T);
for(int cas=1;cas<=T;cas++){
int n,m;
scanf("%d%d",&n,&m);
printf("Case %d: ",cas);
int ans=n*m/2;
ans=max(ans,n*m-ans);
if(n==1||m==1)ans=max(ans,n*m);
else if(n==2||m==2)ans=max(ans,2*(2*(max(n,m)/4)+min(2,max(n,m)%4)));
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: