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

Problem Setter: Jane Alam Jan

规律题

假设n∗m是偶数且都大于2

答案是n∗m/2

假设n和m都是奇数且都大于2

答案就是一半的行放m/2+1个,还有一半放m/2个

假设n m 都小于等于2

n(m)为1,答案就是m(n)

m(n)有一个为2,那么我们能够考虑能够分出多少个2*2的格子

设有x个,答案是(x/2+x % 2)∗4

剩下来可能有一个2*1的,这时假设x是奇数,不能放,假设x是偶数能够放

/*************************************************************************
> File Name: LightOJ1010.cpp
> Author: ALex
> Mail: zchao1995@gmail.com
> Created Time: 2015年06月08日 星期一 14时24分24秒
************************************************************************/ #include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector> using namespace std; const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL; int main() {
int t, icase = 1;
scanf("%d", &t);
while (t--) {
int n, m;
scanf("%d%d", &n, &m);
int ans = 0;
if (n >= 3 && m >= 3) {
if (n * m % 2 == 0) {
ans = n * m / 2;
}
else {
int s = m / 2 + 1;
ans += (n / 2 + 1) * s;
ans += (n / 2) * (s - 1);
}
}
else {
if (n == 1) {
ans = m;
}
else if (m == 1) {
ans = n;
}
else {
if (m == 2) {
swap(n, m);
}
if (m <= 3) {
ans = 4;
}
else {
int cnt = m / 2;
ans = (cnt / 2 + cnt % 2) * 4;
if (m % 2 && cnt % 2 == 0) {
ans += 2;
}
}
}
}
printf("Case %d: %d\n", icase++, ans);
}
return 0;
}

LightOJ1010---Knights in Chessboard (规律题)的更多相关文章

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

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

  2. Codeforces - 规律题 [占坑]

    发现自己容易被卡水题,需要强行苟一下规律题 CF上并没有对应的tag,所以本题集大部分对应百毒搜索按顺序刷 本题集侧重于找规律的过程(不然做这些垃圾题有什么用) Codeforces - 1008C ...

  3. Lightoj 1010 - Knights in Chessboard

    1010 - Knights in Chessboard    PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: ...

  4. ACM_送气球(规律题)

    送气球 Time Limit: 2000/1000ms (Java/Others) Problem Description: 为了奖励近段时间辛苦刷题的ACMer,会长决定给正在机房刷题的他们送气球. ...

  5. hdoj--1005--Number Sequence(规律题)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

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

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

  7. 洛谷 P1876 开灯(思维,枚举,规律题)

    P1876 开灯 题目背景 该题的题目是不是感到很眼熟呢? 事实上,如果你懂的方法,该题的代码简直不能再短. 但是如果你不懂得呢?那...(自己去想) 题目描述 首先所有的灯都是关的(注意是关!),编 ...

  8. Codeforces 959E. Mahmoud and Ehab and the xor-MST 思路:找规律题,时间复杂度O(log(n))

    题目: 解题思路 这题就是0,1,2...n-1总共n个数字形成的最小生成树. 我们可以发现,一个数字k与比它小的数字形成的异或值,一定可以取到k与所有正整数形成的异或值的最小值. 要计算n个数字的情 ...

  9. Visible Lattice Points(规律题)【数学规律】

    Visible Lattice Points 题目链接(点击) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9031   ...

随机推荐

  1. ACdream 1114(莫比乌斯反演)

    传送门:Number theory 题意:给n个数,n 和 每个数的范围都是 1---222222,求n个数中互质的对数. 分析:处理出每个数倍数的个数cnt[i],然后进行莫比乌斯反演,只不过这里的 ...

  2. c++程序猿经典面试题

    1.请问i的值会输出什么? #include"iostream.h" int i=1; void main() { int i=i; cout<<i<<en ...

  3. Oracle 11g服务详解

    装上Oracle之后大家都会感觉到我们的电脑慢了下来,如何提高计算机的速度呢?我们应该打开必要的服务,关闭没有用的服务.下面是Oracle服务的详解: Oracle ORCL VSS Writer S ...

  4. javascript它【蛇系列】第一弹:简单的蛇实现

    参考博客:http://blog.csdn.net/sunxing007/article/details/4187038 上面的博客是一个参考,竟第一次做.真让自己盲人摸象做不出来. 只是我在其上做了 ...

  5. Django写的投票系统3(转)

    Django的管理面板默认是不开启的,所以我们需要进行一些设置工作1.在INSTALLED_APPS里面把 django.contrib.admin 前面的注释去掉2.运行 python manage ...

  6. follow through

    follow through是什么意思_follow through的翻译_音标_读音_用法_例句 - 必应 Bing Dictionary Web Images Videos Maps News D ...

  7. 《火球——UML大战需求分析》(第1章 大话UML)——1.3 行为型的UML(Behavior Diagram)

    说明: <火球——UML大战需求分析>是我撰写的一本关于需求分析及UML方面的书,我将会在CSDN上为大家分享前面几章的内容,总字数在几万以上,图片有数十张.欢迎你按文章的序号顺序阅读,谢 ...

  8. Eclipse常用热键

    ,Ctrl+D 删除选中的几行 ,Alt+上下箭头 移动选中的代码块 ,Alt+左右箭头 回退 前进 ,Alt+Shift+上下箭头 复制选中的代码块 ,sysout+Ctrl space 生成Sys ...

  9. 安卓---项目中插入百度地图sdk

    百度地图 应用里面 自带地图 搜房网 下载百度地图的sdk 熟悉api 注冊百度开发人员的账号 2.12 仅仅要有一个ak就能够 高版本号须要提供应用程序的包名和签名返回开发人员的序列号 使用百度地图 ...

  10. MYSQL高可用(HA)随想

    记得在上一篇文章“Java集群--大型网站是怎样解决多用户高并发访问的”的结尾处本人阐述了数据库的高可用的一种方案----实现主从部署,那么今天,就让我聊聊本人关于数据库的一些所思所想吧! 下面是本人 ...