您的位置:首页 > 其它

The Power of Xiangqi(水题)

2012-11-24 10:01 411 查看

The Power of Xiangqi

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 284 Accepted Submission(s): 145



[align=left]Problem Description[/align]



Xiangqi is one of the most popular two-player board games in China. The game represents a battle between two armies with the goal of capturing the enemy’s “general” piece.

Now we introduce some basic rules of Xiangqi. Xiangqi is played on a 10×9 board and the pieces are placed on the intersections (points). There are two groups of pieces marked by black or red Chinese characters, belonging to the two players separately. During
the game, each player in turn moves one piece from the point it occupies to another point. No two pieces can occupy the same point at the same time. A piece can be moved onto a point occupied by an enemy piece, in which case the enemy piece is "captured" and
removed from the board. When the general is in danger of being captured by the enemy player on the enemy player’s next move, the enemy player is said to have "delivered a check". If the general's player can make no move to prevent the general's capture by
next enemy move, the situation is called “checkmate”.

Each player has 7 kinds of pieces in this game. Their names, offense power and symbol letters are shown in the table below:



Now show you the pieces of red player and black player, you are going to find out which player has the larger total offense power. Since Ma and Pao working together can have good effect, if a player has no Ma or no Pao, or has neither, his total offense power
will be decreased by one. But the total offense power can't be decreased to zero, it is at least one.

[align=left]Input[/align]
The first line is an integer T ( T <= 20) meaning there are T test cases.

For each test case: The first line shows which pieces the red player has. It begins with an integer n ( 0 < n <= 16) meaning the number of pieces.

Then n letters follows, all separated by one or more blanks. Each letter is a symbol letter standing for a piece, as shown in the table above.

The second line describes the situation of the black player, in the same format as the first line.

[align=left]Output[/align]
For each test case, if the red player has more offense power, then print "red". If the black player has more offense power, then print "black". If there is a tie, print "tie".

[align=left]Sample Input[/align]

3
2 A B
2 A B
7 A A B C D D F
7 A A B B C C F
5 A A B B F
3 A B F

[align=left]Sample Output[/align]

tie
black
red

[align=left]Source[/align]
2012 Asia Hangzhou Regional Contest

Statistic | Submit | Discuss |
Note

因为大小写出错,还WA了一次。。。



#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define LL long long
#define MAXI 2147483647
#define MAXL 9223372036854775807
#define eps (1e-8)
#define dg(i) cout << "*" << i << endl;

using namespace std;

int main()
{
const int power[7] = {16, 7, 8, 1, 1, 2, 3};
int T, n, R, B;
char c;
bool ma, pao;
scanf("%d", &T);
while(T--)
{
R = B = 0;
scanf("%d", &n);
ma = pao = 0;
while(n--)
{
cin >> c;
R += power[c - 'A'];
if(c == 'C') pao = 1;
else if(c == 'B') ma = 1;
}
if(pao + ma != 2 && R > 1) R--;
scanf("%d", &n);
ma = pao = 0;
while(n--)
{
cin >> c;
B += power[c - 'A'];
if(c == 'C') pao = 1;
else if(c == 'B') ma = 1;
}
if(pao + ma != 2 && B > 1) B--;
if(B > R) puts("black");
else if(B == R) puts("tie");
else puts("red");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: