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 ...
随机推荐
- hdu1151+poj2594(最小路径覆盖)
传送门:hdu1151 Air Raid 题意:在一个城镇,有m个路口,和n条路,这些路都是单向的,而且路不会形成环,现在要弄一些伞兵去巡查这个城镇,伞兵只能沿着路的方向走,问最少需要多少伞兵才能把所 ...
- Extjs 3.4 和 web SSH(Ajaxterm)-howge-ChinaUnix博客
Extjs 3.4 和 web SSH(Ajaxterm)-howge-ChinaUnix博客 Extjs 3.4 和 web SSH(Ajaxterm) 2013-04-07 15:20:17 ...
- cocos2.2.3 HelloCpp TestCpp android 环境搭建 编译
cygwin make PATH->E:\cygwin\bin JAVA_HOME->C:\Program Files\Java\jdk1.8.0_05 Eclipse->Windo ...
- 已知直线上的两点 A(x1, y1), B(x2, y2) 和另外一点 C(x0, y0),求C点到直线的距离。
数学知识太差,一点点积累,高手勿喷. 1. 先求出AB向量 a = ( x2-x1, y2-y1 ) 2. 求AB向量的单位方向向量 b = √((x2-x1)^2 + (y2-y1)^2)) a1 ...
- POJ2155:Matrix(二维树状数组,经典)
Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...
- cisco san交换机配置
1.配置交换机的管理地址switch(config)# interface mgmt 0 switch(config-if)# ip adress 192.168.100.108 255.255.25 ...
- Macosx Setdns
通过C语言接口在Mac App内部对系统的DNS配置进行改动. Mac OS X设置DNS代码 演示样例代码setDNS.c内容例如以下: #include <SystemConfigurati ...
- SQLiteDatabase和Contentprovider
SQLiteDatabase和Contentprovider这两个数据库,我一般是用前面一个,喜欢它的操作数据库的语句,简单明了,可惜有时遇到数据库同步的问题,有时我们需要在一个数据库下建立多个表,多 ...
- XP下採用DirectShow採集摄像头
转载请标明是引用于 http://blog.csdn.net/chenyujing1234 欢迎大家提出意见,一起讨论! 须要演示样例源代码的请独自联系我. 前提: 摄像头能正常工作.摄像头有创建di ...
- Android涉及到的设计模式(转)
1.适配器模式:ListView或GridView的Adapter 简介:不同的数据提供者使用一个适配器来向一个相同的客户提供服务. 2.建造者模式:AlertDialog.Builder 简介:可以 ...