HDU 4461

The Power of Xiangqi

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1659    Accepted Submission(s): 870


Problem Description

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.
 

Input
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.
 

Output
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".
 

Sample Input
  
  
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
 

Sample Output
  
  
tie black red
 

Source
 
 
 给你象棋里各个子,问红赢还是黑赢。
攻击力如图。
有个小坑。
象棋里有马后炮无解(马的距离离将军两格,一般情况下马后炮是必杀之局)之说。
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
注意这句话。
马和炮在一起将更好的发挥,如果缺少其中一个,或者都没有,攻击力减一。
OK
上代码
#include <stdio.h>
int main()
{ 
    int t;
    scanf("%d",&t);
    while(t--)
    {
        char s[3];
        int x,i;
        scanf("%d",&x);
        int r=0;
        int b=0;
        int f1,f2;    
        f1=f2=0;
        for(i=0;i<x;i++)
        {
            scanf("%s",s);
            if(s[0]=='A')
                r+=16;
            if(s[0]=='B')
                r+=7,
                f1=1;
            if(s[0]=='C')
                r+=8,
                f2=1;
            if(s[0]=='D')
                r+=1;
            if(s[0]=='E')
                r+=1;
            if(s[0]=='F')
                r+=2;
            if(s[0]=='G')
                r+=3;
        }
        if(!f1 || !f2)
            r--;    //减一
        scanf("%d",&x);
        f1=f2=0;
        for(i=0;i<x;i++)
        {
            scanf("%s",s);
            if(s[0]=='A')
                b+=16;
            if(s[0]=='B')
                b+=7,
                f1=1;
            if(s[0]=='C')
                b+=8,
                f2=1;
            if(s[0]=='D')
                b+=1;
            if(s[0]=='E')
                b+=1;
            if(s[0]=='F')
                b+=2;
            if(s[0]=='G')
                b+=3;
        }
        if(!f1 || !f2)
            b--;   //减一。
        if(b==r)
            printf("tie\n");
        else if(b>r)
            printf("black\n");
        else
            printf("red\n");
    }
    return 0;
    
}

[ Copy to Clipboard ]    [ Save to File]




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值