• HDU 1528 Card Game Cheater(打扑克)


    Description:

    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
    题意:两个人Adam,Eve在一起打扑克牌,本来两个人是要按照顺序出牌的,但是由于Adam的牌放在桌面上,而Eve的牌放在下面,所以时间长了Eve就知道了Adam出牌的规律,由此Eve也知道自己该如何出牌来得到更高的分数,谁的牌大,谁得1分,现在问Eve用最好的方案来得到的最高的分数。
     
    比牌大小的规则:两个人的出的牌假设都是只有两个字符的字符串a,b,那么当a[0]<b[0]或者(a[0]==b[0]&&a[1]<b[1])时Eve赢。由于Eve可以改变自己出牌的顺序,所以我们可以先将两个人的牌按照从小到大排序,然后在b中找比a中大的牌,这样依次进行,当任意一方没有办法找到牌来出时结束查找。(前提是让Eve尽可能的得到更高的分数)
     
    #include<stdio.h>
    #include<string.h>
    #include<queue>
    #include<math.h>
    #include<stdlib.h>
    #include<algorithm>
    using namespace std;
    
    const int N=1e6+10;
    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    
    typedef long long LL;
    
    char str1[20]={"23456789TJQKA"}; ///在这两个str字符串中下标较小的元素也是较小的,这样便于比较
    char str2[20]={"CDSH"};
    char s1[50][50], s2[50][50];
    
    void Sort(char a[], char b[]) ///判断a是否>b,如果是则交换
    {
        int ida1, ida2, idb1, idb2, i; 
        char ch[50];
    
        for (i = 0; i < 13; i++)
        {
            if (str1[i] == a[0]) ida1 = i; ///ida1代表a[0]在str1中的位置
            if (str1[i] == b[0]) idb1 = i; ///idb1代表b[0]在str1中的位置
        }
        for (i = 0; i < 4; i++)
        {
            if (str2[i] == a[1]) ida2 = i; ///ida2代表a[1]在str2中的位置
            if (str2[i] == b[1]) idb2 = i; ///idb2代表b[1]在str2中的位置
        }
    
        if (ida1 > idb1) ///下标大,对应的元素就大
        {
            strcpy(ch, a);
            strcpy(a, b);
            strcpy(b, ch);
        }
        else if (ida1 == idb1)
        {
            if (ida2 > idb2)
            {
                strcpy(ch, a);
                strcpy(a, b);
                strcpy(b, ch);
            }
        }
    }
    
    int Judge(char a[], char b[]) ///判断b是否>a
    {
        int ida1, ida2, idb1, idb2, i;
    
        for (i = 0; i < 13; i++)
        {
            if (str1[i] == a[0]) ida1 = i;
            if (str1[i] == b[0]) idb1 = i;
        }
        for (i = 0; i < 4; i++)
        {
            if (str2[i] == a[1]) ida2 = i;
            if (str2[i] == b[1]) idb2 = i;
        }
    
        if (ida1 < idb1) return 1;
        if (ida1 == idb1 && ida2 < idb2) return 1;
    
        return 0;
    }
    
    int main ()
    {
        int T, n, i, j, ans;
    
        scanf("%d", &T);
    
        while (T--)
        {
            ans = 0;
    
            scanf("%d", &n);
            for (i = 0; i < n; i++)
                scanf("%s", s1[i]);
            for (i = 0; i < n; i++)
                scanf("%s", s2[i]);
    
            for (i = 0; i < n-1; i++)
            {
                for (j = i+1; j < n; j++)
                {
                    Sort(s1[i], s1[j]); ///由于牌的排序比较麻烦,所以我们可以采用冒泡排序,每次比较两个牌的大小
                    Sort(s2[i], s2[j]);
                }
            }
    
            i = j = 0;
            while (i < n && j < n) ///任意一方无法找到合适的牌出,就结束
            {
                if (Judge(s1[i], s2[j])) ///如果在s2中找到比s1[i]大的牌,分数+1,双方都能出一张牌i++,j++
                {
                    i++;
                    j++;
                    ans++;
                }
                else j++; ///由于两个数组都是排过序的,所以s2[j]当这张牌不能大于s1[i]时,我们需要j++,继续在s2中查找,那么试想当Adam出了一张牌,而我们不能在s2中找到比它大的牌,那么这种查找就可以结束了,因为Adam剩下的牌会更大
            }
    
            printf("%d
    ", ans);
        }
    
        return 0;
    }
  • 相关阅读:
    Redis学习笔记(三):Redis常见命令
    Redis学习笔记(一):Redis安装与配置
    Redis学习笔记(二):Redis介绍
    微服务 第八章 SpringBoot多数据源的配置(通过Spring Data JPA 的方式)
    微服务 第七章 SpringBoot多数据源的配置(通过JdbcTemplate的方式)
    微服务 第六章 springboot 通过Spring-data-jpa 配置Oracle数据源(Spring-data-jpa详细介绍)
    微服务 第六章 springboot 通过Spring-data-jpa 配置Oracle数据源(简单步骤)
    java通过jdbc对数据库进行增删改查(摘录)
    ---awk 调shell 命令的方法
    ---Linux 10 年的硕果累累啊!
  • 原文地址:https://www.cnblogs.com/syhandll/p/4950809.html
Copyright © 2020-2023  润新知