• hdu 1528 Card Game Cheater (二分匹配)


    Card Game Cheater

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 1072    Accepted Submission(s): 564


    Problem 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
     
    Source
     
    Recommend
    8600   |   We have carefully selected several similar problems for you:  1507 1498 1533 1083 1530 
     

    题意:

        分别给出k张牌,第一个字符为点数,第二个为花色,求第二组和第一组怎么搭配可以获得最多的分数。(比之大可得一分)

    二分匹配:

        用map记录牌的点数,然后暴力出边,在进行二分匹配得解。

     1 //0MS    256K    1366 B    C++
     2 #include<iostream>
     3 #include<map>
     4 #define N 55
     5 using namespace std;
     6 int g[N][N];
     7 int match[N];
     8 int vis[N];
     9 int n;
    10 map<char,int>M;
    11 void init()
    12 {
    13     M['2']=10;
    14     M['3']=20;
    15     M['4']=30;
    16     M['5']=40;
    17     M['6']=50;
    18     M['7']=60;
    19     M['8']=70;
    20     M['9']=80;
    21     M['T']=90;
    22     M['J']=100;
    23     M['Q']=110;
    24     M['K']=120;
    25     M['A']=130;
    26     M['C']=1;
    27     M['D']=2;
    28     M['S']=3;
    29     M['H']=4;
    30 }
    31 int dfs(int x)
    32 {
    33     for(int i=0;i<n;i++){
    34         if(!vis[i] && g[x][i]){
    35             vis[i]=1;
    36             if(match[i]==-1 || dfs(match[i])){
    37                 match[i]=x;
    38                 return 1;
    39             }
    40         }
    41     }
    42     return 0;
    43 }
    44 int hungary()
    45 {
    46     int ret=0;
    47     memset(match,-1,sizeof(match));
    48     for(int i=0;i<n;i++){
    49         memset(vis,0,sizeof(vis));
    50         ret+=dfs(i);
    51     }
    52     return ret;
    53 }
    54 int main(void)
    55 {
    56     int t;
    57     char a[N][5],b[N][5];
    58     init();
    59     scanf("%d",&t);
    60     while(t--)
    61     {
    62         memset(g,0,sizeof(g));
    63         scanf("%d",&n);
    64         for(int i=0;i<n;i++)
    65             scanf("%s",a[i]);
    66         for(int i=0;i<n;i++){
    67             scanf("%s",b[i]);
    68             for(int j=0;j<n;j++)
    69                 if(M[a[j][0]]+M[a[j][1]]<M[b[i][0]]+M[b[i][1]])
    70                     g[i][j]=1;
    71         }
    72         printf("%d
    ",hungary());
    73     }
    74     return 0;
    75 }
  • 相关阅读:
    poj1014 hdu1059 Dividing 多重背包
    浏览器开发工具
    Linux dirname、basename 指令
    linux ar命令
    gcc创建和使用静态库、动态库
    -DDEBUG编译标记
    sigaction函数解析
    Signal ()函数详细介绍 Linux函数
    Linux makefile 教程 非常详细,且易懂
    初始用户组,有效用户组,初始用户,有效用户
  • 原文地址:https://www.cnblogs.com/GO-NO-1/p/3749092.html
Copyright © 2020-2023  润新知