HDU4461 UVALive6379 The Power of Xiangqi【水题】

The Power of Xiangqi

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


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
32 A B2 A B7 A A B C D D F 7 A A B B C C F5 A A B B F3 A B F
 

Sample Output
tieblackred
 

Source


Regionals 2012 >> Asia - Hangzhou


问题链接HDU4461 UVALive6379 The Power of Xiangqi

问题简述

  中国象棋的棋子有相应的能力值。给出红黑方各自拥有的棋子。一方获胜条件是当且仅当能力值之和大于对方,输出能力值总和的比较结果。

问题分析

  需要注意,红黑双方如果不同时具有马和炮则能力值需要减一。

程序说明

  这里给出两个略有不同的程序。

题记:(略)

参考链接:(略)


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

/* HDU4461 UVALive6379 The Power of Xiangqi */

#include <iostream>
#include <stdio.h>

using namespace std;

int power[] = {16, 7, 8, 1, 1, 2, 3};

char mygetchar()
{
    char c;
    while((c = getchar()) == ' ' || c == '\t' || c == '\n');
    return c;
}

int main()
{
    int t, n;
    scanf("%d", &t);
    while(t--) {
        int cnt1 = 0, cnt2 = 0, ma, pao, c;

        ma = pao = 0;
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) {
            c = mygetchar() - 'A';
            cnt1 += power[c];
            if(c == 1)
                ma = 1;
            else if(c == 2)
                pao = 1;
        }
        if(ma + pao != 2)
            cnt1--;

        ma = pao = 0;
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) {
            c = mygetchar() - 'A';
            cnt2 += power[c];
            if(c == 1)
                ma = 1;
            else if(c == 2)
                pao = 1;
        }
        if(ma + pao != 2)
            cnt2--;

        if(cnt1 == cnt2)
            printf("tie\n");
        else if(cnt1 < cnt2)
            printf("black\n");
        else
            printf("red\n");
    }

    return 0;
}



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

/* HDU4461 UVALive6379 The Power of Xiangqi */

#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int power[] = {16, 7, 8, 1, 1, 2, 3};
int vis[sizeof(power) / sizeof(int)];

char mygetchar()
{
    char c;
    while((c = getchar()) == ' ' || c == '\t' || c == '\n');
    return c;
}

int main()
{
    int t, n;
    scanf("%d", &t);
    while(t--) {
        int cnt1 = 0, cnt2 = 0, c;

        memset(vis, 0, sizeof vis);
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) {
            c = mygetchar() - 'A';
            cnt1 += power[c];
            vis[c] = 1;
        }
        if(vis[1] + vis[2] != 2)
            cnt1--;

        memset(vis, 0, sizeof vis);
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) {
            c = mygetchar() - 'A';
            cnt2 += power[c];
            vis[c] = 1;
        }
        if(vis[1] + vis[2] != 2)
            cnt2--;

        if(cnt1 == cnt2)
            printf("tie\n");
        else if(cnt1 < cnt2)
            printf("black\n");
        else
            printf("red\n");
    }

    return 0;
}







阅读更多
换一批

没有更多推荐了,返回首页