UVA 696 - How Many Knights (规律)
来源:互联网 发布:win与mac键盘对照 编辑:程序博客网 时间:2024/05/21 21:42
How Many Knights
The knight is a piece used in chess, a game played on a board with squares arranged in rows and columns. A knight attacks pieces that are either (a) two rows and one column away from its position, or (b) one row and two columns away from its position. The following diagram illustrates this. The square marked N represents the position of the knight, and the squares marked X indicate the squares that are under attack.
In this problem you are to determine the largest number of knights that can be placed on a board with M rows and N columns so that no knight is attacking any other. M and N will each be no larger than 500.
Input
The input consists of pairs of integers giving values for M and N, followed by a pair of zeroes.Output
For each input pair, display the number of rows and columns in the board, and the number of knights that can be appropriately placed.Sample Input
2 35 54 70 0
Sample Output
4 knights may be placed on a 2 row 3 column board.13 knights may be placed on a 5 row 5 column board.14 knights may be placed on a 4 row 7 column board.
题意:给定n * m棋盘,问最多放几个马
思路:找规律, 分情况讨论, n || m == 1 n || m == 2 其他。三种情况。
代码:
#include <stdio.h>int n, m, ans;int main() { while (~scanf("%d%d", &n, &m) && n + m) {if (n == 1) ans = m;else if (m == 1) ans = n;else if (n == 2) ans = m / 4 * 4 + ((m % 4 * 2) >= 4 ? 4 : (m % 4 * 2));else if (m == 2) ans = n / 4 * 4 + ((n % 4 * 2) >= 4 ? 4 : (n % 4 * 2));else ans = (m * n + 1) / 2;printf("%d knights may be placed on a %d row %d column board.\n", ans, n, m); } return 0;}
- UVA 696 - How Many Knights (规律)
- UVa 696 - How Many Knights
- uva 696 - How Many Knights
- UVA 696 How Many Knights
- UVA - 696 How Many Knights
- UVa 696 How Many Knights (想法题)
- UVA696 - How Many Knights(数论)
- uva 10790 How Many Points of Intersection?(几何规律)
- How Many Calls? UVA
- uva 10518 How Many Calls?(矩阵快速幂)(找规律)
- Uva 10303 How Many Trees?
- uva 10183 how many fibs
- uva 10183 How Many Fibs
- UVa 10183 - How Many Fibs?
- UVA 10183 How Many Fibs?
- UVA 10518 How Many Calls?
- UVA 10303 How Many Trees?
- UVa 10183 - How Many Fibs?
- 字符串常见问题总结(二)
- 关于点击劫持(clickjacking)的一些信息
- 【黑马程序员】java多线程创建的俩中方法总结
- Oracle问题总结
- 日结账单和周结账单
- UVA 696 - How Many Knights (规律)
- FPGA芯片结构
- 关于发展民用航天技术
- s3c2410_gpio_setpin()与s3c2410_gpio_cfgpin()函数定义
- C语言函数调用参数压栈顺序
- Lua表的构造
- Implementing a Recursive Procedure with IA32 and Y86 Assembly Code
- 软引用、弱引用、虚引用 总结
- Python yield详解