Codeforces Round #294 (Div. 2) -- A. A and B and Chess
2015-03-01 17:58
337 查看
A. A and B and Chess
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
the queen's weight is 9,
the rook's weight is 5,
the bishop's weight is 3,
the knight's weight is 3,
the pawn's weight is 1,
the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input
The input contains eight lines, eight characters each — the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R',
the bishop — as'B', the knight — as 'N', the pawn — as 'P',
the king — as 'K'.
The black pieces are denoted as 'q', 'r', 'b',
'n', 'p', 'k',
respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack
and so on.
Output
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black"
if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Sample test(s)
input
output
input
output
input
output
Note
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.
思路:简单题,不过有坑点,注意the knight — as 'N',这里还被hack一次,╮(╯▽╰)╭
AC代码:
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
the queen's weight is 9,
the rook's weight is 5,
the bishop's weight is 3,
the knight's weight is 3,
the pawn's weight is 1,
the king's weight isn't considered in evaluating position.
The player's weight equals to the sum of weights of all his pieces on the board.
As A doesn't like counting, he asked you to help him determine which player has the larger position weight.
Input
The input contains eight lines, eight characters each — the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R',
the bishop — as'B', the knight — as 'N', the pawn — as 'P',
the king — as 'K'.
The black pieces are denoted as 'q', 'r', 'b',
'n', 'p', 'k',
respectively.
An empty square of the board is marked as '.' (a dot).
It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack
and so on.
Output
Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black"
if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal.
Sample test(s)
input
...QK... ........ ........ ........ ........ ........ ........ ...rk...
output
White
input
rnbqkbnr pppppppp ........ ........ ........ ........ PPPPPPPP RNBQKBNR
output
Draw
input
rppppppr ...k.... ........ ........ ........ ........ K...Q... ........
output
Black
Note
In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16.
思路:简单题,不过有坑点,注意the knight — as 'N',这里还被hack一次,╮(╯▽╰)╭
AC代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #define LL long long using namespace std; char a[10]; int val(char c) { if(c == 'Q' || c == 'q') return 9; else if(c == 'R' || c == 'r') return 5; else if(c == 'B' || c == 'b') return 3; else if(c == 'N' || c == 'n') return 3; else if(c == 'P' || c == 'p') return 1; else return 0; } int main() { int w = 0, b = 0; int t = 8; while(t--) { scanf("%s", a); int len = strlen(a); for(int i = 0; i < len; i++) { if(a[i] <= 'Z' && a[i] >= 'A') w += val(a[i]); else if(a[i] <= 'z' && a[i] >= 'a') b += val(a[i]); } } if(w == b) printf("Draw\n"); else if(w > b) printf("White\n"); else if(w < b) printf("Black\n"); return 0; }
相关文章推荐
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings [dp 前缀和 ]
- Codeforces Round #294 (Div. 2) -- C. A and B and Team Training
- Codeforces Round #294 (Div. 2)D. A and B and Interesting Substrings
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings
- Codeforces Round #379 (Div. 2) D. Anton and Chess 模拟
- Codeforces Round #313 (Div. 1) C - Gerald and Giant Chess dp
- Codeforces Round #379 (Div. 2)-D. Anton and Chess
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 博弈
- Codeforces Round #294 (Div. 2)-C. A and B and Team Training
- Codeforces Round #294 (Div. 2) -- B. A and B and Compilation Errors
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball&D. Vasya and Chess
- Codeforces Round #294 (Div. 2) E. A and B and Lecture Rooms(倍增LCA+树形DP)
- Codeforces Round #294 (Div. 2)D - A and B and Interesting Substrings 字符串
- Codeforces Round #379 (Div. 2) D. Anton and Chess 水题
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 镜面对称 博弈论
- Codeforces Round #313 (Div. 2) Problem E - Gerald and Giant Chess
- Codeforces Round #442 (Div. 2) E. Danil and a Part-time Job DFS序+树链剖分+线段树区间^
- Codeforces Round #260 (Div. 2)B. Fedya and Maths
- Codeforces Round #332 (Div. 2)A. Patrick and Shopping 水
- Codeforces Round #267 (Div. 2) C. George and Job