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 ...
随机推荐
- win8 远程桌面 你得凭证不工作
今天在在登录azure远程桌面时,一直提示你的凭证不工作, 按照网上各种教程都不行, 后来发现在win8中用户名结构中,需要加上本机电脑名比如:“win8\administrator”.
- 金融界高富帥現身快男北京唱區 陳樂:我拿生活養夢想__娛樂新聞_Yes娛樂
http://m.baidu.com/tc?pn=15&bd_page_type=1&pu=sz%401320%5F1001%2Cta%40iphone%5F2%5F4%2E1%5F3 ...
- Hama学习总结
Hama学习笔记 1. Hama定义 Hama是基于HDFS上的BSP模型实现,其执行不须要MapReduce. 例证例如以下: 在单点调试的Hama系统上,仅仅执行NameNode.Da ...
- curl的封装
首先要搭建一个httpserver,这里採用tomcat6为例: 过程:新建一个Servlet,并使用tomcat的默认port号8080监听,最后写一个jsp来測试能否够訪问该server 1)新建 ...
- windows服务的创建、安装和调试
1.创建 windows服务 项目 文件 -> 新建项目 -> 已安装的模板 -> Visual C# -> windows ,在右侧窗口选择"windows 服 ...
- linux进程解析--进程的退出及销毁
一进程的退出: 当一个进程运行完毕或者因为触发系统异常而退出时,最终会调用到内核中的函数do_exit(),在do_exit()函数中会清理一些进程使用的文件描述符,会释放掉进程用户态使用的相关的物理 ...
- pygame系列_font游戏字体
在pygame游戏开发中,一个友好的UI中,漂亮的字体是少不了的 今天就给大伙带来有关pygame中字体的一些介绍说明 首先我们得判断一下我们的pygame中有没有font这个模块 1 if not ...
- Eclipse常用设置汇总
设置编码: . 设置字体: 依次展开 Window->Preferences->Java->Code Style->Formatter 在右边窗口中找到Edit ·找到Lin ...
- 在Eclipse在使用JUnit4单元测试(0基础知识)
自这篇文章: http://www.devx.com/Java/Article/31983/0/page/1 我们在编写大型程序的时候,须要写成千上万个方法或函数.这些函数的功能可能非常强大,但我们在 ...
- Windows Phone开发(6):处理屏幕方向的改变
原文:Windows Phone开发(6):处理屏幕方向的改变 俺们都知道,智能手机可以通过旋转手机来改变屏幕的显示方向,更多的时候,对于屏幕方向的改变,我们要做出相应的处理,例如,当手机屏幕方向从纵 ...