uva 696 - How Many Knights
题目链接:uva 696 - How Many Knights
题目大意:给出一个n * m的网格,计算最多可以放置几个国际象棋中的骑士。
解题思路:分成三类来讨论:
1)min(n, m) == 1, 也就是无论怎么摆也不会影响到其他的骑士。
2)min(n, m) == 2, 这是将网格将网格分成2*4的若干部分,每个部分的前半部分放置骑士,主要注意模4后剩余部分的处理。
3)n *m的网格上间隔摆放(就是对应的黑格子或者白格子)(n * m - 1)/ 2
#include <stdio.h>
int f(int n, int m) {
if (n < m) return f(m, n);
else if (m == 1) return n;
else if (m == 2) {
return (n / 4) * 4 + ((n % 4 > 1) ? 2 : n % 4) * 2;
}
else return (n * m + 1) / 2;
}
int main () {
int r, c;
while (scanf("%d%d", &r, &c), r + c) {
printf("%d knights may be placed on a %d row %d column board.\n", f(r, c), r, c);
}
return 0;
}
uva 696 - How Many Knights的更多相关文章
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- uva 3523 Knights of the Round Table
题意:给你n,m n为有多少人,m为有多少组关系,每组关系代表两人相互憎恨,问有多少个骑士不能参加任何一个会议. 白书算法指南 对于每个双联通分量,若不是二分图,就把里面的节点标记 #include ...
- UVA 1364 - Knights of the Round Table (获得双连接组件 + 二部图推理染色)
尤其是不要谈了些什么,我想A这个问题! FML啊.....! 题意来自 kuangbin: 亚瑟王要在圆桌上召开骑士会议.为了不引发骑士之间的冲突. 而且可以让会议的议题有令人惬意的结果,每次开会前都 ...
- UVA它11292 - Dragon of Loowater
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- UVA 11292 Dragon of Loowater(简单贪心)
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- POJ2942 UVA1364 Knights of the Round Table 圆桌骑士
POJ2942 洛谷UVA1364(博主没有翻墙uva实在是太慢了) 以骑士为结点建立无向图,两个骑士间存在边表示两个骑士可以相邻(用邻接矩阵存图,初始化全为1,读入一对憎恨关系就删去一条边即可),则 ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
随机推荐
- pygame系列_pygame安装
在接下来的blog中,会有一系列的文章来介绍关于pygame的内容,所以把标题设置为pygame系列 在这篇blog中,主要描述一下我们怎样来安装pygame 可能很多人像我一样,发现了pygame是 ...
- Python—对Excel进行读写操作
学习Python的过程中,我们会遇到Excel的读写问题.通过搜索得知,我们可以使用xlwt module将数据写入Excel表格,使用xlrd module从Excel读取数据.下面介绍如何实现使用 ...
- git服务器安装和配置
http://www.cnblogs.com/dee0912/p/5815267.html
- GCC 对C语言的扩展
http://www.cnblogs.com/emituofo/archive/2012/07/20/2600995.html http://blog.csdn.net/andyhuabing/art ...
- 分布式中使用redis进行session共享
摘要 在asp.net web中,session经常用来存储当前用户信息,或者通过session进行登录权限的验证.如果是一台服务器,session的使用没问题,如果使用nginx等实现反向代理,将站 ...
- authentication not supported Connect to TFS Git from Xamarin Studio (non-hosted, locally installed TFS 2013)
There are several instructions on how to connect to TFS Git from Xamarin Studio if you're using the ...
- 如何使用C#关键字const,readonly,static
如果有一个值不太会变化,我们经常使用const和readonly,这2者有何不同呢?有时候,我们也会在readonly之前加上关键字static,这又意味着什么呢? const ● const默认是静 ...
- Maven私仓配置
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://mav ...
- Weblogic下启用Gzip压缩
一.首先,去http://sourceforge.net/projects/filterlib网站下载tk-filters-1.0.1.zip. 二.解压这个tk-filters-1.0.1.zip压 ...
- 让Mac风扇面对PD不再疯狂
对于所有喜欢Mac操作系统的用户来说,如果办公环境必须使用Windows及Windows程序,那一定会非常崩溃,因为你很可能使用了Parallels Desktop来运行你的Windows虚拟机,那么 ...