UVA278 UVALive5586 Chess【水题】

Almost everyone knows the problem of putting eight queens on an 8×8 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 m × n 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 (4 ≤ m ≤ 10) and n (4 ≤ n ≤ 10), 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
2
r 6 7
k 8 8
Sample Output
6
32

Regionals 1993 >> Europe - Southwestern

问题链接UVA278 UVALive5586 Chess
问题简述:(略)
问题分析
    给定棋子的种类和棋盘的大小m*n,问说在该棋盘上最多能放几个棋子,使之棋子之间不能互相攻击。棋子有4类,‘r’, ‘k’, ‘Q’, ‘K’分别表示Rook(车), Knight(骑士,马),Queen(皇后)和King(王)。
    本题按行棋规则进行计算,车和和皇后按行或列的最小值即可,王隔一行隔一列放即可,马隔一个位置放即可。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA278 UVALive5586 Chess */

#include <bits/stdc++.h>

using namespace std;

const int N = 128;
char s[N];

int main()
{
    int t, x, y;
    char b;
    scanf("%d", &t);
    getchar();
    while(t--) {
        cin.getline(s, N - 1);
        sscanf(s, "%c%d%d", &b, &x, &y);
        if(b == 'r' || b == 'Q')
            printf("%d\n", min(x, y));
        else if(b == 'k')
            printf("%d\n", (x * y + 1) / 2);
        else if(b == 'K')
            printf("%d\n",((x + 1) / 2) * ((y + 1) / 2));
    }

    return 0;
}
上一篇:C.One Piece


下一篇:Codeforces 1383D - Rearrange(构造)