zoukankan      html  css  js  c++  java
  • HDU1258&&1962--Card Game Cheater

    Card Game Cheater
    Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 159 Accepted Submission(s): 117


    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

    求E尽可能多地得到分数,只要E的牌大于A的牌就连一边

    求最大匹配

      1 #include<cstdio>
      2 #include<iostream>
      3 #include<algorithm>
      4 #include<cstring>
      5 #include<cmath>
      6 using namespace std;
      7 
      8 struct Node
      9 {
     10     int num;
     11     char str[101];
     12 }A[101],E[101];
     13 int Link[101][101];
     14 int cy[101];
     15 int mk[101];
     16 
     17 int Getpoint(Node a)
     18 {
     19     int sum=0;
     20     if(a.str[0]>='2'&&a.str[0]<='9')sum+=(a.str[0]-'0')*10;
     21     if(a.str[0]=='T')sum+=10*10;
     22     if(a.str[0]=='J')sum+=10*11;
     23     if(a.str[0]=='Q')sum+=10*12;
     24     if(a.str[0]=='K')sum+=10*13;
     25     if(a.str[0]=='A')sum+=10*14;
     26     if(a.str[1]=='H')sum+=4;
     27     if(a.str[1]=='S')sum+=3;
     28     if(a.str[1]=='D')sum+=2;
     29     if(a.str[1]=='C')sum+=1;
     30     return sum;
     31 }
     32 
     33 int t;
     34 int num;
     35 void init()
     36 {
     37     memset(Link,0,sizeof(Link));
     38     memset(cy,0xff,sizeof(cy));
     39     memset(mk,0,sizeof(mk));
     40 }
     41 
     42 int path(int u)
     43 {
     44     int v;
     45     for(v=1;v<=num;v++)
     46     {
     47         if(!mk[v]&&Link[u][v])
     48         {
     49             mk[v]=1;
     50             if(cy[v]==-1||path(cy[v]))
     51             {
     52                 cy[v]=u;
     53                 return 1;
     54             }
     55         }
     56     }
     57     return 0;
     58 }
     59 
     60 int maxmatch()
     61 {
     62     int i;
     63     int sum=0;
     64     for(i=1;i<=num;i++)
     65     {
     66         memset(mk,0,sizeof(mk));
     67         sum+=path(i);
     68     }
     69     return sum;
     70 }
     71 
     72 int main()
     73 {
     74     scanf("%d",&t);
     75     while(t--)
     76     {
     77         init();
     78         scanf("%d",&num);
     79         int i;
     80         for(i=1;i<=num;i++)
     81         {
     82             scanf("%s",A[i].str);
     83             A[i].num=Getpoint(A[i]);
     84         }
     85         for(i=1;i<=num;i++)
     86         {
     87             scanf("%s",E[i].str);
     88             E[i].num=Getpoint(E[i]);
     89         }
     90         int j;
     91         for(i=1;i<=num;i++)
     92         {
     93             for(j=1;j<=num;j++)
     94             {
     95                 if(E[i].num>A[j].num)
     96                 {
     97                     Link[i][j]=1;
     98                 }
     99             }
    100         }
    101         int ans=maxmatch();
    102         printf("%d
    ",ans);
    103     }
    104     return 0;
    105 }
    View Code
  • 相关阅读:
    springmvc log4j 配置
    intellij idea maven springmvc 环境搭建
    spring,property not found on type
    intellij idea maven 工程生成可执行的jar
    device eth0 does not seem to be present, delaying initialization
    macos ssh host配置及免密登陆
    centos7 搭建 docker 环境
    通过rest接口获取自增id (twitter snowflake算法)
    微信小程序开发体验
    gitbook 制作 beego 参考手册
  • 原文地址:https://www.cnblogs.com/zafuacm/p/3222045.html
Copyright © 2011-2022 走看看