zoukankan      html  css  js  c++  java
  • hdu 5228 枚举

    题意:在前往ZJOI2015一试的路上,ZCC在同Fsygd打德州扑克时输光了所有的筹码。不过ZCC最近学会了一些黑技术。现在,他能够在游戏过程中更换任何他想要更换的牌。
    ZCC想要通过更换尽量少的牌得到同花顺。 称五张牌构成了同花顺,当且仅当它们的数值连续,花色一致。请告诉ZCC他至少需要更换多少张牌。 在题目中,牌的花色用一个大写字母('A', 'B', 'C', 'D')来表示,而数值用数字('1', '2', , '13')来表示。 注意数字1代表ace,在德州扑克中是最大的牌。"1 2 3 4 5" 和 "10 11 12 13 1" 都被认为是连续的。而"11 12 13 1 2"并不是。

    同花顺的情况不多,不妨枚举所有同花顺的情况,看五张牌中有几张已经在给出的牌中出现了,剩下的牌就是必须要换掉的。枚举同花顺时,可以先枚举花色,再枚举顺子中最小的牌。

    枚举所有同花顺,看当前序列满足的最多情况

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<queue>
     7 #include<map>
     8 using namespace std;
     9 #define MOD 1000000007
    10 const int INF=0x3f3f3f3f;
    11 const double eps=1e-5;
    12 typedef long long ll;
    13 #define cl(a) memset(a,0,sizeof(a))
    14 #define ts printf("*****
    ");
    15 const int MAXN=1005;
    16 int n,m,tt;
    17 char s[6][5];
    18 int get(char ss[])
    19 {
    20     int len=strlen(ss);
    21     if(len==2)
    22     {
    23         return ss[1]-'0';
    24     }
    25     else
    26         return (ss[1]-'0')*10+(ss[2]-'0');
    27 }
    28 int main()
    29 {
    30     int i,j,k;
    31     #ifndef ONLINE_JUDGE
    32     freopen("1.in","r",stdin);
    33     #endif
    34     scanf("%d",&tt);
    35     while(tt--)
    36     {
    37         scanf("%s %s %s %s %s",s[1],s[2],s[3],s[4],s[5]);
    38         int Max=0;
    39         for(i=1;i<=4;i++)   //枚举花色
    40         {
    41             for(j=1;j<=13;j++)  //起点
    42             {
    43                 int tot=0;
    44                 for(k=1;k<=5;k++)    //5个符合条件的同花顺
    45                 {
    46                     for(int d=1;d<=5;d++)   //5张牌
    47                     {
    48                         int q=j+k-1;
    49                         if(q==14)   q=1;
    50                         if(s[d][0]-'A'+1==i&&get(s[d])==q)
    51                         {
    52                             tot++;
    53                         }
    54                     }
    55                 }
    56                 Max=max(tot,Max);
    57             }
    58         }
    59         printf("%d
    ",5-Max);
    60     }
    61 }
  • 相关阅读:
    各种文件的mime类型
    LeetCode_122. Best Time to Buy and Sell Stock II
    LeetCode_121. Best Time to Buy and Sell Stock
    LeetCode_119. Pascal's Triangle II
    LeetCode_118. Pascal's Triangle
    LeetCode_112. Path Sum
    LeetCode_111. Minimum Depth of Binary Tree
    LeetCode_110. Balanced Binary Tree
    LeetCode_108. Convert Sorted Array to Binary Search Tree
    LeetCode_107. Binary Tree Level Order Traversal II
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/4516713.html
Copyright © 2011-2022 走看看