UVa 278 Chess (想法题)
来源:互联网 发布:ubuntu双系统引导界面 编辑:程序博客网 时间:2024/06/05 14:22
278 - Chess
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=214
Almost everyone knows the problem of putting eight queens on an chessboard such that no Queen can take another Queen. Jan Timman (a famous Dutch chessplayer) wants to know the maximum number of chesspieces of one kind which can be put on an board with a certain size such that no piece can take another. Because it's rather difficult to find a solution by hand, he asks your help to solve the problem.
He doesn't need to know the answer for every piece. Pawns seems rather uninteresting and he doesn't like Bishops anyway. He only wants to know how many Rooks, Knights, Queens or Kings can be placed on one board, such that one piece can't take any other.
Input
The first line of input contains the number of problems. A problem is stated on one line and consists of one character from the following set r, k, Q, K, meaning respectively the chesspieces Rook, Knight, Queen or King. The character is followed by the integers m ( ) and n ( ), meaning the number of rows and the number of columns or the board.
Output
For each problem specification in the input your program should output the maximum number of chesspieces which can be put on a board with the given formats so they are not in position to take any other piece.
Note: The bottom left square is 1, 1.
Sample Input
2r 6 7k 8 8
Sample Output
632
此题是UVa 696 的升级版。
r和Q都是max(m,n)
k的公式详见这里。
K就是一个点周围8个不能有其他点。
完整代码:
/*0.009s*/#include <cstdio>int cal(char ch, int m, int n){if (m > n) return cal(ch, n, m);if (ch == 'r' || ch == 'Q') return m;if (ch == 'K') return ((n + 1) >> 1) * ((m + 1) >> 1);if (m == 1) return n;if (m == 2) return (n >> 2 << 2) + ((n % 4 == 3 ? 2 : n % 4) << 1);return (n * m + 1) >> 1;}int main(){int t, m, n;char ch;scanf("%d", &t);getchar();while (t--){scanf("%c%d%d", &ch, &m, &n);getchar();printf("%d\n", cal(ch, m, n));}return 0;}
- UVa 278 Chess (想法题)
- UVa 278 - Chess
- UVA 278 - Chess(数论)
- uva 278 - Chess(计数问题)
- UVa 10730 Antiarithmetic? (想法题)
- UVa 10152 ShellSort (想法题)
- UVa 571 Jugs (想法题)
- UVA 6862 Triples 想法题
- UVa 11538 - Chess Queen
- Chess Queen UVA 11538
- UVA 11538 Chess Queen
- Uva-11538-Chess Queen
- UVa 11538 Chess Queen
- UVa 11538 - Chess Queen
- uva 11538 Chess Queen
- UVA 11538 Chess Queen
- UVA 11538 - Chess Queen
- uva 11538 Chess Queen
- android天气查询(二)之网络json数据的获取
- POJ 1050 To the Max
- JavaScript的变量
- fuser命令用法详解
- 给定一个字符串的语句,里面包含空格(多个),把语句中的空格改为1个空格,格式化输出这个句子
- UVa 278 Chess (想法题)
- C语言的条件编译
- “蓝牙是个金矿,将掀起新一轮技术淘金热!
- Linq to DataTable 合并相同的二个DataTable 且已重复的行不合并
- Ubuntu下的RabbitVCS
- 白话经典算法系列之六 快速排序 快速搞定
- 消息定义结构详解
- 一个整数数组(正负,0),找出这个数组的最大子序列
- windows资源管理器文件无法自动刷新