Lightoj 1010 - Knights in Chessboard
| Time Limit: 1 second(s) | Memory Limit: 32 MB |
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 |

白块上放马或者黑块上放马能得到最优解。注意有1和2的情况特殊讨论。
/* ***********************************************
Author :guanjun
Created Time :2016/6/13 20:53:50
File Name :1010.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int n,m;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int T,ans;
cin>>T;
for(int t=;t<=T;t++){
scanf("%d%d",&n,&m);
if(n>m)swap(n,m);
int x,y;
if(n&){
x=(n+)/;//第一个填 1
}
else x=n/;
if(m&){
y=(m+)/;
}
else y=m/;
ans=x*y+(n-x)*(m-y); if(n==)ans=m;
if(n==){
ans=m/*;
if((m%)==)ans+=;
if((m%)>=)ans+=;
}
printf("Case %d: %d\n",t,max(max(n,m),ans));
}
return ;
}
Lightoj 1010 - Knights in Chessboard的更多相关文章
- Lightoj 1010 - Knights in Chessboard (胡搞)
题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1010 题目描述: 有一个n*m的棋盘,根据象棋中马走日字的规则,问此棋盘最多 ...
- LightOJ - 1010 Knights in Chessboard(规律)
题目链接:https://vjudge.net/contest/28079#problem/B 题目大意:给你一个nxm的棋盘,问你最多可以放几个骑士让他们互相攻击不到.骑士攻击方式如下图: 解题思路 ...
- lightoj 1010 (水题,找规律)
lightoj 1010 Knights in Chessboard 链接:http://lightoj.com/volume_showproblem.php?problem=1010 题意:国际象棋 ...
- LightOJ1171 Knights in Chessboard (II)(二分图最大点独立集)
题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1171 Description Given an m x n ches ...
- lightoj 1010
题意,在一个n*n的棋盘上放置一些马,使这些马不能互相攻击,问最多能放多少. 思路:从第一行每隔一个放置一个马即可,注意n=1和n=2的情况要特判. #include<cstdio> in ...
- LightOJ Beginners Problems 部分题解
相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...
- LightOJ 1315 - Game of Hyper Knights(博弈sg函数)
G - Game of Hyper Knights Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & ...
- lightoj 1243 - Guardian Knights 最小费用流
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...
- 【BZOJ1671】[Usaco2005 Dec]Knights of Ni 骑士 BFS
[Usaco2005 Dec]Knights of Ni 骑士 Description 贝茜遇到了一件很麻烦的事:她无意中闯入了森林里的一座城堡,如果她想回家,就必须穿过这片由骑士们守护着的森林.为 ...
随机推荐
- 关于程序计数器(PC)和条件控制转移 引起的性能差异
关于PC(程序计数器) 冯 ·诺伊曼计算机体系结构的主要内容之一就是“程序预存储,计算机自动执行”! 处理器要执行的程序(指令序列)都是以二进制代码序列方式预存储在计算机的存储器中,处理器将这些代码逐 ...
- 【06】sass编译工具(弃)
[06]编译工具(弃) SASS转译工具 除了使用sass命令来转译SASS文件之外,还可以借助第三方工具完成,目前世面上较为流行的转译工具主要有: Compass.app Scout Codekit ...
- pip安装requests库失败
pip install 安装第三方插件是出现Could not fetch URL https://pypi.python.org/simple/pool/: There was a problem ...
- CodeForces 556 --Case of Fake Numbers
B. Case of Fake Numbers time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- linux 常见名词及命令(二)
pwd 用于显示当前的工作目录. cd 用于切换工作路径 cd - 切换到上一次的目录 cd ~ 切换到家目录 cd ~username 切换到其他用户的家目录 cd .. 切换到上级目录 ls 用于 ...
- Python基础之 一 字符编码及转换
python2 / python3编码转换 先上图一张: 说明:python编码转换的流程是 先进行decode解码,然后进行encode编码 解释: u'你好' -->带u表示为unicod ...
- [Bzoj1499][NOI2005]瑰丽华尔兹[简单DP]
1499: [NOI2005]瑰丽华尔兹 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 1714 Solved: 1042[Submit][Status ...
- 使用Spring Data Redis操作Redis(集群版)
说明:请注意Spring Data Redis的版本以及Spring的版本!最新版本的Spring Data Redis已经去除Jedis的依赖包,需要自行引入,这个是个坑点.并且会与一些低版本的Sp ...
- ultraiso:usb-hdd+ v2
http://cn.ezbsystems.com/ultraiso/download.htm 普通隐藏:建立一个LBA前置的PBR包含表头的活动分区.高端隐藏:建立一个LBA后置的PBR包含表头的活动 ...
- 【stl学习笔记】set、multiset
set和multiset会根据特定的排序准则,自动将元素排序.两者不同处在于multiset允许元素重复而set不允许 在使用set或multiset之前,必须先加入头文件<set> se ...