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是偶数能够放

  1. /*************************************************************************
  2. > File Name: LightOJ1010.cpp
  3. > Author: ALex
  4. > Mail: zchao1995@gmail.com
  5. > Created Time: 2015年06月08日 星期一 14时24分24秒
  6. ************************************************************************/
  7. #include <functional>
  8. #include <algorithm>
  9. #include <iostream>
  10. #include <fstream>
  11. #include <cstring>
  12. #include <cstdio>
  13. #include <cmath>
  14. #include <cstdlib>
  15. #include <queue>
  16. #include <stack>
  17. #include <map>
  18. #include <bitset>
  19. #include <set>
  20. #include <vector>
  21. using namespace std;
  22. const double pi = acos(-1.0);
  23. const int inf = 0x3f3f3f3f;
  24. const double eps = 1e-15;
  25. typedef long long LL;
  26. typedef pair <int, int> PLL;
  27. int main() {
  28. int t, icase = 1;
  29. scanf("%d", &t);
  30. while (t--) {
  31. int n, m;
  32. scanf("%d%d", &n, &m);
  33. int ans = 0;
  34. if (n >= 3 && m >= 3) {
  35. if (n * m % 2 == 0) {
  36. ans = n * m / 2;
  37. }
  38. else {
  39. int s = m / 2 + 1;
  40. ans += (n / 2 + 1) * s;
  41. ans += (n / 2) * (s - 1);
  42. }
  43. }
  44. else {
  45. if (n == 1) {
  46. ans = m;
  47. }
  48. else if (m == 1) {
  49. ans = n;
  50. }
  51. else {
  52. if (m == 2) {
  53. swap(n, m);
  54. }
  55. if (m <= 3) {
  56. ans = 4;
  57. }
  58. else {
  59. int cnt = m / 2;
  60. ans = (cnt / 2 + cnt % 2) * 4;
  61. if (m % 2 && cnt % 2 == 0) {
  62. ans += 2;
  63. }
  64. }
  65. }
  66. }
  67. printf("Case %d: %d\n", icase++, ans);
  68. }
  69. return 0;
  70. }

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. VSTO之旅系列(二):创建Excel解决方案

    原文:VSTO之旅系列(二):创建Excel解决方案 本专题概要 引言 创建VSTO项目 Excel对象模型 创建Excel外接程序 创建Excel文档级自定义项 小结 一.引言 也许很多朋友都没有听 ...

  2. oschina 手机/移动开发

    手机/移动开发 Android UI 组件(167) React Native 相关(8) 网站客户端(16) NativeScript 插件(18) iPhone/iPad开发工具(16) WP7开 ...

  3. hdu3062(two-sat)

    传送门:Party 题意:有n对夫妻被邀请参加一个聚会,因为场地的问题,每对夫妻中只有1人可以列席.在2n 个人中,某些人之间有着很大的矛盾(当然夫妻之间是没有矛盾的),有矛盾的2个人是不会同时出现在 ...

  4. C语言文件操作之fgets()

        来说一说fgets(..)函数.     原型  char *  fgets(char * s, int n,FILE *stream);     參数:          s: 字符型指针, ...

  5. firebug登陆之数据包分析

    登陆之数据包分析 工具: python-urllib2   |  firefox+firebug或者chrome,用浏览器打开登陆页面之后,按F12键会默认打开开发者工具或者启动firebug,点击n ...

  6. Python数据结构-序表

    序表解包: list=['aa','bb','cc'] [a1,a2,a3]=list

  7. ecshop首页调用指定分类的所有产品(指定一级调二级)

    第一种方法 第一 在/includes/lib_goods.php下增加如下代码,用过网上的直接换掉就可以 function index_get_cat_id_goods_best_list($cat ...

  8. Java开发环境的基本设置

    作为Java的刚開始学习的人,不知道其它的刚開始学习的人有没有和我一样的感受:用Java开发须要配置这么复杂 的环境.太难了.第一次配置时,一团混乱.Oracle监听服务打不开了,PLSql连接不上O ...

  9. iOS Dev (59) 高度自适应的UITextView

    iOS Dev (59) 高度自适应的UITextView 作者:阿锐 地址:http://blog.csdn.net/prevention - 例如以下 _inputTextView 为一个 UIT ...

  10. 染色法判断是否是二分图 hdu2444

    用染色法判断二分图是这样进行的,随便选择一个点, 1.把它染成黑色,然后将它相邻的点染成白色,然后入队列 2.出队列,与这个点相邻的点染成相反的颜色 根据二分图的特性,相同集合内的点颜色是相同的,即 ...