1010 - Knights in Chessboard
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

白块上放马或者黑块上放马能得到最优解。注意有1和2的情况特殊讨论。

/* ***********************************************
Author :guanjun
Created Time :2016/6/13 20:53:50
File Name :1010.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int n,m;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int T,ans;
cin>>T;
for(int t=;t<=T;t++){
scanf("%d%d",&n,&m);
if(n>m)swap(n,m);
int x,y;
if(n&){
x=(n+)/;//第一个填 1
}
else x=n/;
if(m&){
y=(m+)/;
}
else y=m/;
ans=x*y+(n-x)*(m-y); if(n==)ans=m;
if(n==){
ans=m/*;
if((m%)==)ans+=;
if((m%)>=)ans+=;
}
printf("Case %d: %d\n",t,max(max(n,m),ans));
}
return ;
}

Lightoj 1010 - Knights in Chessboard的更多相关文章

  1. Lightoj 1010 - Knights in Chessboard (胡搞)

    题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1010 题目描述: 有一个n*m的棋盘,根据象棋中马走日字的规则,问此棋盘最多 ...

  2. LightOJ - 1010 Knights in Chessboard(规律)

    题目链接:https://vjudge.net/contest/28079#problem/B 题目大意:给你一个nxm的棋盘,问你最多可以放几个骑士让他们互相攻击不到.骑士攻击方式如下图: 解题思路 ...

  3. lightoj 1010 (水题,找规律)

    lightoj 1010 Knights in Chessboard 链接:http://lightoj.com/volume_showproblem.php?problem=1010 题意:国际象棋 ...

  4. LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)

    题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...

  5. lightoj 1010

    题意,在一个n*n的棋盘上放置一些马,使这些马不能互相攻击,问最多能放多少. 思路:从第一行每隔一个放置一个马即可,注意n=1和n=2的情况要特判. #include<cstdio> in ...

  6. LightOJ Beginners Problems 部分题解

    相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...

  7. LightOJ 1315 - Game of Hyper Knights(博弈sg函数)

    G - Game of Hyper Knights Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & ...

  8. lightoj 1243 - Guardian Knights 最小费用流

    #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...

  9. 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS

    [Usaco2005 Dec]Knights of Ni 骑士 Description  贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...

随机推荐

  1. 【HDU 5934】Bomb(强连通缩点)

    Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding r ...

  2. gitlab+jenkins+docker自动构建

    docker容器部署gitlab: sudo docker run --detach \ --hostname git.gitlab.com \ --net=host \ --publish 9443 ...

  3. 把以100000+4位随机码的登录账号(比如1000001234),赋予制单页面的权限,怎么写sql啊

    insert into sys_user_role (user_id,role_id,office_id)  select id,'000101100000000004UP',company_id f ...

  4. Leetcode 284.顶端迭代器

    顶端迭代器 给定一个迭代器类的接口,接口包含两个方法: next() 和 hasNext().设计并实现一个支持 peek() 操作的顶端迭代器 -- 其本质就是把原本应由 next() 方法返回的元 ...

  5. 公路修建(Prim)

    洛谷传送门 这道水题告诉了我,堆优化的prim有时还不如朴素prim快... 居然记错时间复杂度了,我也真是菜. #include <cstdio> #include <queue& ...

  6. 魔咒词典(hdu 1880)

    Problem Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔 ...

  7. 【HDOJ6318】Swaps and Inversions(树状数组)

    题意: 给定一串数组,其中含有一个逆序对则需要花费x,交换相邻两个数需要花费y,输出最小花费. n<=1e5,-1e9<=a[i]<=1e9 思路: #include<cstd ...

  8. 51nod1135 原根

    原根判定:$m>2$,$\varphi (m)$的不同素数是$q_1,q_2,……,q_s$,$(g,m)=1$,则$g$是$m$的一个原根的充要条件是$g^{\frac{\varphi(m)} ...

  9. ubuntu,CentOS永久修改主机名

    1.查看主机名 在Ubuntu系统中,快速查看主机名有多种方法: 其一,打开一个GNOME终端窗口,在命令提示符中可以看到主机名,主机名通常位于“@”符号后: 其二,在终端窗口中输入命令:hostna ...

  10. Spring Cloud(9):Config配置中心

    Config配置中心作用简单来讲:统一配置,方便管理 开源配置中心: 1.百度Disconf 2.阿里Diamand 3.Spring Cloud Config 搭建Config-Server 快速上 ...