题目链接: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的更多相关文章

  1. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  2. uva 3523 Knights of the Round Table

    题意:给你n,m n为有多少人,m为有多少组关系,每组关系代表两人相互憎恨,问有多少个骑士不能参加任何一个会议. 白书算法指南 对于每个双联通分量,若不是二分图,就把里面的节点标记 #include ...

  3. UVA 1364 - Knights of the Round Table (获得双连接组件 + 二部图推理染色)

    尤其是不要谈了些什么,我想A这个问题! FML啊.....! 题意来自 kuangbin: 亚瑟王要在圆桌上召开骑士会议.为了不引发骑士之间的冲突. 而且可以让会议的议题有令人惬意的结果,每次开会前都 ...

  4. UVA它11292 - Dragon of Loowater

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  5. UVA 11292 Dragon of Loowater(简单贪心)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  6. POJ2942 UVA1364 Knights of the Round Table 圆桌骑士

    POJ2942 洛谷UVA1364(博主没有翻墙uva实在是太慢了) 以骑士为结点建立无向图,两个骑士间存在边表示两个骑士可以相邻(用邻接矩阵存图,初始化全为1,读入一对憎恨关系就删去一条边即可),则 ...

  7. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  8. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  9. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

随机推荐

  1. CentOS7.0安装Nginx-1.12.0

    一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.openssl-devel.pcre-devel和zlib ...

  2. Codeforces Round #287 (Div. 2) A. Amr and Music 水题

    A. Amr and Music time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  3. offset大家族(一)

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Git提交空文件夹的技巧

    这个只能说是技巧不能说是方法,原理是在每个空文件夹新建一个.gitignore文件,然后提交. 快捷命令: find . -type d -empty -exec touch {}/.gitignor ...

  5. XStream转换Java对象与XML

    1.引入需要的jar包,在pom.xml中配置依赖 <dependency> <groupId>com.thoughtworks.xstream</groupId> ...

  6. Windows界面编程第四篇 异形窗体 高富帅版 ---博客

    http://blog.csdn.net/morewindows/article/details/8451638

  7. UI----------------Toggle

    Is On:是否已经勾选上了 Toggle Transition:渐变效果 Graphic:勾选标志的图,就是那个勾 Group:多选组 On Value Changed:当选项改变时,触发事件 多选 ...

  8. 比較两个 List 的值是否相等

    public static <T extends Comparable<T>> boolean compare(List<T> a, List<T> b ...

  9. Coursera课程《大家的编程》(Python入门)中课程目录

    Getting Started with Python Getting Started with Python is the first course in the specialization Py ...

  10. linux的chmod,chown命令详解

    指令名称 : chmod 使用权限 : 所有使用者 使用方式 : chmod [-cfvR] [--help] [--version] mode file... 说明 : Linux/Unix 的档案 ...