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. .NET Core使用EPPlus简单操作Excel(简单实现导入导出)

    1.前言 EPPlus是一个使用Open Office XML(xlsx)文件格式,能读写Excel 2007/2010 文件的开源组件,在导出Excel的时候不需要电脑上安装office,它的一个缺 ...

  2. 大数据学习——yum练习安装mysql

    1. 安装mysql 服务器端: yum install mysql-server yum install mysql-devel 2. 安装mysql客户端: yum install mysql 3 ...

  3. 遇到的Ajax相关问题

  4. XTU 二分图和网络流 练习题 B. Uncle Tom's Inherited Land*

    B. Uncle Tom's Inherited Land* Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %I ...

  5. css装饰文本框input

    在web程序前端页面中,<input>恐怕是用的最多的html元素了,各个需要录入信息的场合都会用到它,一般都会用css来修饰一下使得它更好看. 原始的不加修饰的文本框像下面,有些单调,页 ...

  6. CentOS6 CentOS7 yum安装图形界面

    CentOS6 yum安装图形界面yum groupinstall -y "Desktop" "Desktop Platform" "Desktop ...

  7. [luoguP1227] [JSOI2008]完美的对称(sort)

    传送门 排序! #include <cstdio> #include <iostream> #include <algorithm> #define N 20001 ...

  8. hdu 4710

    #include<stdio.h> #include<math.h> __int64 min(__int64 a,__int64 b) { return a<b?a:b; ...

  9. 【LibreOJ10121】与众不同(RMQ,二分)

    题意: 思路: C++ #include<map> #include<set> #include<cmath> #include<cstdio> #in ...

  10. windows 下安装Apache httpd 只需三步

    1.下载 Apache 官网地址:http://httpd.apache.org/docs/current/platform/windows.html#down 找到这个, 看到这几个选项: Apac ...