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 ...
随机推荐
- python IDLE 自动提示功能
\Python27\Lib\idlelib\目录下 config-extensions.def文件修改等待时间 [AutoComplete] enable=1 popupwait=2000(2000表 ...
- iOS 视频组件
公司最近要在项目里新增一个随手拍的功能,所以呢我在网上找了个比较不错的demo,顺便研究了下它的代码结构.感谢大神的分享,如有侵权,请告知哦!
- Python如何import文件夹下的文件
Python的import包含文件功能就跟PHP的include类似,但更确切的说应该更像是PHP中的require,因为Python里的import只要目标不存在就报错程序无法往下执行.要包含目录里 ...
- HDU 4730 We Love MOE Girls (2013成都网络赛,签到水题)
We Love MOE Girls Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Leetcode 树 Populating Next Right Pointers in Each Node II
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie Populating Next Right Pointers in Each Node II ...
- C语言每日小练(四)——勇者斗恶龙
勇者斗恶龙 你的王国里有一条n个头的恶龙,你希望雇佣一些骑士把它杀死(砍掉全部的头). 村里有m个骑士能够雇佣.一个能力值为x的骑士能够砍掉恶龙一个致敬不超过x的头,且须要支付x个金币. 怎样雇佣骑士 ...
- java、js中实现无限层级的树形结构(类似递归)
js中: var zNodes=[ {id:0,pId:-1,name:"Aaaa"}, {id:1,pId:0,name:"A"}, {id:11,pId:1 ...
- struts2必要的包
想正常使用struts2.1.6,至少需要如下6 个jar包: struts2-core-2.1.6.jar freemarker-2.3.13.jar commons-logging-1.0.4.j ...
- how to configure logback for Mybatis to print my SQL
To log SQL statements for particular mybatis mapper set DEBUG (TRACE to see query parameters and res ...
- JMS基本概念之一
The Java Message Service(JMS) API is a messaging standard that allows application components based o ...