LightOJ1010---Knights in Chessboard (规律题)
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 (规律题)的更多相关文章
- LightOJ - 1010 Knights in Chessboard(规律)
题目链接:https://vjudge.net/contest/28079#problem/B 题目大意:给你一个nxm的棋盘,问你最多可以放几个骑士让他们互相攻击不到.骑士攻击方式如下图: 解题思路 ...
- Codeforces - 规律题 [占坑]
发现自己容易被卡水题,需要强行苟一下规律题 CF上并没有对应的tag,所以本题集大部分对应百毒搜索按顺序刷 本题集侧重于找规律的过程(不然做这些垃圾题有什么用) Codeforces - 1008C ...
- Lightoj 1010 - Knights in Chessboard
1010 - Knights in Chessboard PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: ...
- ACM_送气球(规律题)
送气球 Time Limit: 2000/1000ms (Java/Others) Problem Description: 为了奖励近段时间辛苦刷题的ACMer,会长决定给正在机房刷题的他们送气球. ...
- hdoj--1005--Number Sequence(规律题)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...
- 洛谷 P1876 开灯(思维,枚举,规律题)
P1876 开灯 题目背景 该题的题目是不是感到很眼熟呢? 事实上,如果你懂的方法,该题的代码简直不能再短. 但是如果你不懂得呢?那...(自己去想) 题目描述 首先所有的灯都是关的(注意是关!),编 ...
- Codeforces 959E. Mahmoud and Ehab and the xor-MST 思路:找规律题,时间复杂度O(log(n))
题目: 解题思路 这题就是0,1,2...n-1总共n个数字形成的最小生成树. 我们可以发现,一个数字k与比它小的数字形成的异或值,一定可以取到k与所有正整数形成的异或值的最小值. 要计算n个数字的情 ...
- Visible Lattice Points(规律题)【数学规律】
Visible Lattice Points 题目链接(点击) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9031 ...
随机推荐
- undefined reference to `sin'问题解决
作者:zhanhailiang 日期:2014-10-25 使用gcc编译例如以下代码时报"undefined reference to `sin'": #include < ...
- 读取生产环境go语言的最佳实践展示
近期看了一篇关于go产品开发最佳实践的文章,go-in-procution.作者总结了他们在用go开发过程中的非常多实际经验,我们非常多事实上也用到了.鉴于此,这里就简单的写写读后感,兴许我也争取能将 ...
- zoj3329(概率dp)
题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3754 题意:有三个骰子,分别有k1,k2,k3个面. 每次掷骰子,如 ...
- hdu1709(母函数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1709 题意: 给你一个n,表示n个物品,下面有n个数,表示n个物品的重量,然后进行称量,每个物品只有一 ...
- 【Energy Big Data】能源互联网和电力大数据
背景 今年的政府工作报告突出了互联网在经济结构转型中的重要地位,报告明白指出:要制定"互联网+"行动计划,推动移动互联网.云计算.大数据.物联网等与现代制造业结合,促进电子商务.工 ...
- Python使用时间戳
1.将字符串的时间转换为时间戳 方法: a = "2013-10-10 23:40:00" 将其转换为时间数组 importtime timeArray = time.strpti ...
- 使用cacti监控服务器
一.cacti安装 cacti需要lamp环境,因此需要首先编译安装lamp环境,安装完成后,下载cacti的zip包,解压到/www/htdocs目录下,创建cacti需要的数据库. 完成上述后,在 ...
- SVN更改登录用户(转)
一) 原地址:http://www.ixna.net/articles/2606 //证书缓存 $ svn list https://host.example.com/repos/project Er ...
- poj2763(树链剖分)
题目链接:http://poj.org/problem?id=2763 题意:定一棵带边权的树,要求支持两种操作:1)询问树中某两点间的距离. 2)修改某条边的权值. 分析:树链剖分,边权修改,路径求 ...
- SVN 的revert操作