HDU-4461-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): 1420    Accepted Submission(s): 775

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

2012 Asia Hangzhou Regional Contest

昨天去实验室刷的水题。。挺简单的,不过还是失误了,输入字符的时候要吸收之后回车,不然就用字符串!

题意:就是算total power , 但是注意了,当没马或没炮或两者都没的时候total power 会减少1,且total power 最少为1!

水题还是要多多注意的!!不然就WA了

代码:

#include <cstdio>
#include <cstring>
using namespace std;
bool A, B;
int fun(char a)
{
	if(a == 'A')return 16;
	if(a == 'B')return 7;
	if(a == 'C')return 8;
	if(a == 'D')return 1;
	if(a == 'E')return 1;
	if(a == 'F')return 2;
	if(a == 'G')return 3;
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		char a[3];
		int n1, n2, sum1=0, sum2=0;
		scanf("%d", &n1);
		A=0; B=0;
		while(n1--)
		{
			scanf("%s", a);
			sum1+=fun(a[0]);
            if(a[0]=='B') A=1;
			if(a[0]=='C') B=1;
		}
		if(A==0||B==0)
		    sum1--;
		if(sum1==0) sum1=1;
		scanf("%d", &n2);
		A=0; B=0;
		while(n2--)
		{
			scanf("%s", a);
			sum2+=fun(a[0]);
			if(a[0]=='B') A=1;
			if(a[0]=='C') B=1;
		}
		if(A==0||B==0)
		    sum2--;
		if(sum2==0) sum2=1;
		if(sum1>sum2) printf("red\n");
		else if(sum1 == sum2) printf("tie\n");
		else if(sum1<sum2) printf("black\n");
	}
	return 0;
}
时间: 2024-11-03 05:34:36

HDU-4461-The Power of Xiangqi的相关文章

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.

hdu 6034 Balala Power!

题目链接:hdu 6034 Balala Power! 题意: 给你n个字符串,都是包含小写字母,现在让你给a~z赋值0~25,使得这些字符串变成的26进制的数的总和最大. 不能有前导0的情况,他们保证至少有一个字母不出现在第一位. 题解: 每个字符对答案的贡献都可以看作一个 26 进制的数字,问题相当于要给这些贡献加一个 0 到 25 的权重使得答案最大.最大的数匹配 25,次大的数匹配 24,依次类推.排序后这样依次贪心即可,唯一注意的是不能出现前导 0. 前导0的具体处理看代码. 1 #i

HDU Integer&#39;s Power(容斥原理)

题意 求[l,r]的最大指数和(1<=l,r<=10^18) 最大指数和(如64=8^2=4^3=2^6,所以64的最大指数和是6) 题解 很明显我们可以先求出[1,n]的最大指数和,然后再作差. 我们可以先求出num[i]代表[1,n]中最大指数为i的数有多少个. 然后枚举全部的i,然后让答案加上i*num[i]: 那么怎么求num[i]呢 我们可以求出[1,n]中指数为x的数有多少个作为num[x]的初步值.这个用n1/x就可以求出(不过要注意精度问题,及其恶心,看代码吧) 然后这个num

HDU 4461:The Power of Xiangqi(水题)

http://acm.hdu.edu.cn/showproblem.php?pid=4461 题意:每个棋子有一个权值,给出红方的棋子情况,黑方的棋子情况,问谁能赢. 思路:注意“ if a player has no Ma or no Pao, or has neither, his total offense power will be decreased by one”这句话即可. 1 #include <cstdio> 2 #include <cstring> 3 #inc

HDU 6034 Balala Power!(贪心+排序)

Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1411    Accepted Submission(s): 239 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters.

2017 Multi-University Training Contest - Team 1 1002&amp;&amp;HDU 6034 Balala Power!【字符串,贪心+排序】

Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2668    Accepted Submission(s): 562 Problem Description Sample Input 1 a 2 aa bb 3 a ba abc Sample Output Case #1: 25 Case #2: 132

hdu 4461 第37届ACM/ICPC杭州赛区I题

题意:给两个人一些棋子,每个棋子有其对应的power,若b没有或者c没有,或者二者都没有,那么他的total power就会减1,total power最少是1,求最后谁能赢 如果b或c出现的话,flag就标记为1,那么在判断的时候如果flag==0,就说明他们没出现过,那么就要-1,然后就wa了,必须要两个变量判断,不知道为什么 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #inclu

HDU 6034 Balala Power!【排序/进制思维】

Balala Power![排序/进制思维] Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 6703    Accepted Submission(s): 1680 Problem Description Talented Mr.Tang has n strings consisting of only lower case cha

HDU 6034 Balala Power! (贪心+坑题)

题意:给定一个 n 个字符串,然后问你怎么给 a-z赋值0-25,使得给定的字符串看成26进制得到的和最大,并且不能出现前导0. 析:一个很恶心的题目,细节有点多,首先是思路,给定个字符一个权值,然后要注意的进位,然后排序,从大到小,给每个字符赋值,如果最后一个出现前导0,就得向前找一个最小的不在首字符的来交换,但不能动了相对的顺序. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <c