ayit第九周训练l题

本文介绍了一个涉及策略和优化的纸牌游戏,两名玩家Adam和Eve使用标准的52张扑克牌进行比赛,Eve拥有预知Adam手牌的能力,目标是通过重新排列自己的牌来最大化得分。文章详细解释了游戏规则、牌面比较方法以及如何通过二分最大匹配算法确定Eve的最佳策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Adam and Eve play a card game using a regular deck of 52 cards. The rules are simple. The players sit on opposite sides of a table, facing each other. Each player gets k cards from the deck and, after looking at them, places the cards face down in a row on the table. Adam’s cards are numbered from 1 to k from his left, and Eve’s cards are numbered 1 to k from her right (so Eve’s i:th card is opposite Adam’s i:th card). The cards are turned face up, and points are awarded as follows (for each i ∈ {1, . . . , k}): 


If Adam’s i:th card beats Eve’s i:th card, then Adam gets one point. 


If Eve’s i:th card beats Adam’s i:th card, then Eve gets one point. 


A card with higher value always beats a card with a lower value: a three beats a two, a four beats a three and a two, etc. An ace beats every card except (possibly) another ace. 


If the two i:th cards have the same value, then the suit determines who wins: hearts beats all other suits, spades beats all suits except hearts, diamond beats only clubs, and clubs does not beat any suit. 

For example, the ten of spades beats the ten of diamonds but not the Jack of clubs. 

This ought to be a game of chance, but lately Eve is winning most of the time, and the reason is that she has started to use marked cards. In other words, she knows which cards Adam has on the table before he turns them face up. Using this information she orders her own cards so that she gets as many points as possible. 

Your task is to, given Adam’s and Eve’s cards, determine how many points Eve will get if she plays optimally. 
 

Input

There will be several test cases. The first line of input will contain a single positive integer N giving the number of test cases. After that line follow the test cases. 

Each test case starts with a line with a single positive integer k <= 26 which is the number of cards each player gets. The next line describes the k cards Adam has placed on the table, left to right. The next line describes the k cards Eve has (but she has not yet placed them on the table). A card is described by two characters, the first one being its value (2, 3, 4, 5, 6, 7, 8 ,9, T, J, Q, K, or A), and the second one being its suit (C, D, S, or H). Cards are separated by white spaces. So if Adam’s cards are the ten of clubs, the two of hearts, and the Jack of diamonds, that could be described by the line 

TC 2H JD 

Output

For each test case output a single line with the number of points Eve gets if she picks the optimal way to arrange her cards on the table. 
 

Sample Input

3
1
JD
JH
2
5D TC
4C 5H
3
2H 3H 4H
2D 3D 4D

Sample Output

1
1
2
#include<stdio.h>
#include<math.h>
#include<string.h>
int n,b1[600],e[600][600],f1[600];
char a[555][4],b[555][4];
int dfs(int x)
{
    int i;
    for(i=0; i<=n; i++)
    {
        if(b1[i]==0&&e[x][i]==1)
        {
            b1[i]=1;
            if(f1[i]==0||dfs(f1[i]))
            {
                f1[i]=x;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    int i,t,j;
    scanf("%d",&t);
    while(t--)
    {
        memset(f1,0,sizeof(f1));
        memset(e,0,sizeof(e));
        memset(a,'\0',sizeof(a));
        memset(b,0,sizeof(b));
        scanf("%d",&n);
        getchar();
        for(i=1; i<=n; i++)
        {
            scanf("%s",&a[i]);
        }
        for(j=1; j<=n; j++)
        {
            scanf("%s",&b[j]);
            char bc=b[j][1];
            if(bc=='H')
                bc='Z';
                int c2;
            if(b[j][0]>'1'&&b[j][0]<='9')
                c2=b[j][0]-'0';
            if(b[j][0]=='T')
                c2=10;
            if(b[j][0]=='J')
                c2=11;
            if(b[j][0]=='Q')
                c2=12;
            if(b[j][0]=='K')
                c2=13;
            if(b[j][0]=='A')
                c2=14;
            for(i=1; i<=n; i++)
            {
                char ac=a[i][1];
                if(ac=='H')
                    ac='Z';
                int c1;
                if(a[i][0]>'1'&&a[i][0]<='9')
                    c1=a[i][0]-'0';
                if(a[i][0]=='T')
                    c1=10;
                if(a[i][0]=='J')
                    c1=11;
                if(a[i][0]=='Q')
                    c1=12;
                if(a[i][0]=='K')
                    c1=13;
                if(a[i][0]=='A')
                    c1=14;
                if(c2>c1||(c2==c1&&bc>ac))
                {
                    e[j][i]=1;
                }

            }
        }
        int s=0;
        for(i=1; i<=n; i++)
        {
            memset(b1,0,sizeof(b1));
            if(dfs(i))
                s++;
        }
        printf("%d\n",s);
    }
    return 0;
}

   类型   二分最大匹配

题意   两个人打牌,Adam 已经将牌按顺序放好,Eve 可以看到 Adam 的牌, Eve 可以优化自己的牌的顺序,使得自己每个位置           的牌赢 Adam 位置上的牌的个数最多,每张牌由 值+类型 构成,值按照 2, 3, 4, 5, 6, 7, 8 ,9, T, J, Q, K, A 的顺序依次增                    大,类型按照  C, D, S, H 的顺序依次增大,一张牌赢拿一分,平局或输掉不拿分,求最多能拿几分

思路     牌是数字+字母混合组成,因此两张牌的比较麻烦可以将每张牌转换成不同的大小,这样每张牌就有一个独特的分数,比              较两张牌的大小就转换为比较两张牌的分数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值