HDU-1528 Card Game Cheater


HZNU-1135 Card Game Cheater


题目描述
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.

输入
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

输出
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.

题目大意:Eve和Adam比牌的大小,牌大的得一分。已知Adam牌的次序,问Eve怎么排自己的牌,使得自己的分值最大。牌的大小为:数值从小到大排序为2, 3, 4, 5, 6, 7, 8 ,9, T, J, Q, K, or A,若数值大小相同则比较花色,从小到大为CDSH。我先是写了一个cmp函数用于比较大小,这道题的难点是,怎么贪心他所能得到的最大分值。,

以下是代码:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <vector>

using namespace std;
bool cmp (char a, char b,char c, char d)
{
    if (a != b)
    {
        if ((a - '0' < 10)&&(b - '0' < 10))
        {
            return b > a;
        }
        if (b == 'T' && ( a - '0' < 10))
        {
            return 1;
        }
        if (b == 'J' && ( ( a - '0' < 10 ) || a == 'T' ) )
        {
            return 1;
        }
        if (b == 'Q' && (( a - '0' < 10 ) || a == 'T' || a == 'J'))
            return 1;
        if (b == 'K' && (( a - '0' < 10 ) || a == 'T' || a == 'J' || a == 'Q'))
            return 1;
        if (b == 'A')
            return 1;
    }
    else
    {
        if (d == 'H')
            return 1;
        if (d == 'S' && (c == 'D' || c == 'C'))
            return 1;
        if (d == 'D' && c == 'C')
            return 1;
    }
    return 0;
}
int main ()
{
    int k;
    cin >> k;
    while(k--)
    {
        int n;
        cin >> n;
        string a[100],e[100];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++)
        {
            cin >> e[i];
        }
        int cnt[100] = {0};
        //算出Eve的每张牌比对方几张牌要大。
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                 if (cmp(a[j][0],e[i][0],a[j][1],e[i][1]))
                 {
                    cnt[i]++;
                 }
            }
        }
        sort(cnt,cnt + n);
        int ans = 0;
        int j = 1;
            for (int i = 0; i <n; i++)
            {
                if(cnt[i] >= j )    // j记录Eve已经比对方大几张。
                {
                    ans++;
                    j++;
                }
            }
        cout << ans<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值