Codeforce 519A - A and B and Chess (我都觉得水)
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.
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.
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.
...QK...
........
........
........
........
........
........
...rk...
White
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
Draw
rppppppr
...k....
........
........
........
........
K...Q...
........
Black
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.
题解:水很深
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <vector> 6 #include <cstdlib> 7 #include <iomanip> 8 #include <cmath> 9 #include <ctime> 10 #include <map> 11 #include <set> 12 using namespace std; 13 #define lowbit(x) (x&(-x)) 14 #define max(x,y) (x>y?x:y) 15 #define min(x,y) (x<y?x:y) 16 #define MAX 100000000000000000 17 #define MOD 1000000007 18 #define pi acos(-1.0) 19 #define ei exp(1) 20 #define PI 3.141592653589793238462 21 #define INF 0x3f3f3f3f3f 22 #define mem(a) (memset(a,0,sizeof(a))) 23 typedef long long ll; 24 const int N=205; 25 const int mod=1e9+7; 26 int main() 27 { 28 char c; 29 int i,j,a=0,b=0; 30 for(i=0;i<8;i++){ 31 for(j=0;j<8;j++){ 32 scanf("%c",&c); 33 if(c=='Q') a+=9; 34 else if(c=='R') a+=5; 35 else if (c=='B'||c=='N') a+=3; 36 else if(c=='P') a++; 37 else if(c=='q') b+=9; 38 else if(c=='r') b+=5; 39 else if(c=='b'||c=='n') b+=3; 40 else if(c=='p') b++; 41 } 42 c=getchar();//这里记得处理 43 } 44 if(a>b) printf("White\n"); 45 else if(b>a) printf("Black\n"); 46 else printf("Draw\n"); 47 return 0; 48 }