LightOJ1010 棋盘上能放的最多马数
来源:互联网 发布:简历制作软件 app 编辑:程序博客网 时间:2024/06/02 05:04
Knights in Chessboard
LightOJ - 1010Given an 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 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.
For each case, print the case number and maximum number of knights that can be placed in the board considering the above restrictions.
3
8 8
3 7
4 10
Case 1: 32
Case 2: 11
Case 3: 20
做法:
对于棋盘,我们会发现,如果我们只把马放在白色的方格内,则任意两个马都不会互相攻击。
这样我们有了第一种放法,全放在白格内或者全放在黑格内。
但是有一些特殊情况。
假如n=min(n,m),m=max(n,m);
如果n=1,那么我们可以在棋盘上全放上棋子。
如果n=2,那么我们可以一次把一个田字格全部放上马,然后间隔一个田字格,然后再放马。
#include <bits/stdc++.h>using namespace std;int main(){ int t,kcase=1;; scanf("%d", &t); while(t--) { int m,n,ans; scanf("%d%d", &m, &n); if(m == 1 || n == 1) ans = m*n; else if(m == 2 || n == 2) { if(m == 2) if(n%4 < 2) ans = (n/4)*4 + (n%4)*2; else ans = (n/4)*4 + 4; if(n == 2) if(m%4 < 2) ans = (m/4)*4 + (m%4)*2; else ans = (m/4)*4 + 4; } else ans = (m*n+1)/2; printf("Case %d: %d\n", kcase++, ans); } return 0;}
- LightOJ1010 棋盘上能放的最多马数
- 【lightoj1010】
- 內固——n*n的棋盘上最多可以放多少个马
- 最多连续数的子集
- 最多连续数的子集
- 出现次数最多的数
- 最多连续数的子集
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- 出现次数最多的数
- CCF 出现最多的数
- 出现次数最多的数
- 出现次数最多的数
- 二叉排序树的实现与输出
- iptables的基本概念和数据包流程图(二)
- Android系统CPU使用率获取(附java代码)
- Android的蓝牙实例代码中找不到REQUEST_ENABLE_BT
- JSP JavaBean
- LightOJ1010 棋盘上能放的最多马数
- 苹果官方UIWindow
- HTML 表单原理
- 青蛙跳台阶----斐波那契数列
- 关联规则(association rule)挖掘与频繁项集挖掘算法Apriori Java实现
- Educational Codeforces Round 13 E. Another Sith Tournament 状压dp
- HDU 2047 2045
- css的继承
- Public Sale