鱼C论坛

 找回密码
 立即注册
查看: 2666|回复: 6

题目54:在扑克游戏中玩家1能赢多少局?

[复制链接]
发表于 2015-6-12 22:55:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

Poker hands

In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way:

  • High Card: Highest value card.
  • One Pair: Two cards of the same value.
  • Two Pairs: Two different pairs.
  • Three of a Kind: Three cards of the same value.
  • Straight: All cards are consecutive values.
  • Flush: All cards of the same suit.
  • Full House: Three of a kind and a pair.
  • Four of a Kind: Four cards of the same value.
  • Straight Flush: All cards are consecutive values of same suit.
  • Royal Flush: Ten, Jack, Queen, King, Ace, in same suit.

The cards are valued in the order:
2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.

If two players have the same ranked hands then the rank made up of the highest value wins; for example, a pair of eights beats a pair of fives (see example 1 below). But if two ranks tie, for example, both players have a pair of queens, then highest cards in each hand are compared (see example 4 below); if the highest cards tie then the next highest cards are compared, and so on.

Consider the following five hands dealt to two players:

QQ20150612-5@2x.png

The file, poker.txt, contains one-thousand random hands dealt to two players. Each line of the file contains ten cards (separated by a single space): the first five are Player 1's cards and the last five are Player 2's cards. You can assume that all hands are valid (no invalid characters or repeated cards), each player's hand is in no specific order, and in each hand there is a clear winner.

How many hands does Player 1 win?

题目:

在扑克游戏中,一局牌由五张牌组成,组成的牌的大小由低向高如下:

  • High Card: 最高值的牌.
  • One Pair: 两张面值一样的牌.
  • Two Pairs: 两个值不同的One Pair.
  • Three of a Kind: 三张面值一样的牌.
  • Straight: 所有的牌面值为连续数值.
  • Flush: 所有的牌花色相同.
  • Full House: Three of a Kind 加一个One Pair.
  • Four of a Kind: 四张牌面值相同.
  • Straight Flush: 所有的牌花色相同并且为连续数值.
  • Royal Flush: 10,J,Q,K和A,并且为相同花色。

牌的面值大小排序如下:
2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.

如果两个玩家的牌具有同样的排序(上面介绍的几种),那么他们牌的大小由手中最大的牌决定。例如,一对 8 比一对 5 大(见下面例一);但是如果两个玩家都用一对 Q,那么他们手中最大的牌就用来比较大小(见下面例四);如果他们最高面值的牌也相等,那么就用次高面值的牌比较,以此类推。

考虑下面的几个例子:

QQ20150612-6@2x.png

文件 p054_poker.txt (29.3 KB, 下载次数: 35) 包含一千局随机牌。每一行包含十张牌(用空格分隔);前五张是玩家 1 的牌,后五张是玩家 2 的牌。 所有的牌都是合理的(没有非法字符或者重复的牌)。每个玩家的牌没有顺序,并且每一局都有明确的输赢。

其中玩家 1 能赢多少局?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-10-14 16:32:33 | 显示全部楼层
这题不是难,是很烦,要考虑很多种情况,写不同条件.
帖子长度关系,省略牌组数据,可以自行粘贴。
376
[Finished in 0.2s]
  1. pokerdata = ['8C','TS','KC','9H','4S','7D','2S','5D','3S','AC','5C','AD','5D','AC','9C','7C','5H','8D','TD','KS','3H','7H','6S','KC','JS','QH','TD','JC','2D','8S','TH','8H',
  2. ######################
  3. ######################
  4. ###~~~省略牌组数据~~~###
  5. ######################
  6. ######################
  7. '2D','JS','QD','AC','9C','JD','7C','6D','TC','6H','6C','JC','3D','3S','QC','KC','3S','JC','KD','2C','8D','AH','QS','TS','AS','KD','3D','JD','8H','7C','8C','5C','QD','6C']

  8. def evalHand(hand):
  9.     values = ['2','3','4','5','6','7','8','9','T','J','Q','K','A']

  10.     flush = 1
  11.     suit = hand[0][1]
  12.     for card in hand:
  13.         if card[1] <> suit:
  14.             flush = 0
  15.             break

  16.     indices = []
  17.     royal = 1
  18.     straight = 1
  19.     for card in hand:
  20.         indices.append(values.index(card[0]))
  21.     indices.sort()
  22.     if indices[4] - indices[0] <> 4 \
  23.        or indices.count(indices[0]) > 1 \
  24.        or indices.count(indices[1]) > 1 \
  25.        or indices.count(indices[2]) > 1 \
  26.        or indices.count(indices[3]) > 1 \
  27.        or indices.count(indices[4]) > 1:
  28.         straight = 0
  29.     if indices[0] <> 8:
  30.         royal = 0

  31.     kinds = []
  32.     for value in indices:
  33.         count = indices.count(value)
  34.         if count > 1:
  35.             kind = [value, count]
  36.             if kind not in kinds:
  37.                 kinds.append(kind)

  38.     if royal and flush:
  39. #        return "royal flush"
  40.         return [9, 0]
  41.     if straight and flush:
  42. #        return "straight flush"
  43.         return [8, indices[4]]
  44.     if len(kinds) == 1 and kinds[0][1] == 4:
  45. #        return "four of a kind"
  46.         return [7, kinds[0][0]]
  47.     if len(kinds) == 2 and (kinds[0][1] + kinds[1][1] == 5):
  48. #        return "full house"
  49.         return [6, kinds[0][0]]
  50.     if flush:
  51. #        return "flush"
  52.         return [5, indices[4]]
  53.     if straight:
  54. #        return "straight"
  55.         return [4, indices[4]]
  56.     if len(kinds) == 1 and kinds[0][1] == 3:
  57. #        return "three of a kind"
  58.         return [3, kinds[0][0]]
  59.     if len(kinds) == 2 and (kinds[0][1] + kinds[1][1] == 4):
  60. #        return "two pair"
  61.         return [2, max(kinds[0][0], kinds[1][0])]
  62.     if len(kinds) == 1 and kinds[0][1] == 2:
  63. #        return "one pair"
  64.         return [1, kinds[0][0]]
  65. #    return "high card"
  66.     return [0, max(indices)]

  67. rounds = []
  68. for rd in range(1000):
  69.     rounds.append(pokerdata[rd*10:rd*10+10])

  70. count = 0
  71. for r in rounds:
  72.     p1 = evalHand(r[0:5])
  73.     p2 = evalHand(r[5:10])
  74.     if p1[0] > p2[0] or (p1[0] == p2[0] and p1[1] > p2[1]):
  75.         count = count + 1

  76. print count
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-25 13:19:15 | 显示全部楼层
本帖最后由 王小召 于 2019-6-25 13:25 编辑

总共进行了: 1000 次比赛
P1赢了: 379 次!
P2赢了: 621 次!
用时:0.156001 秒
  1. import re
  2. import time

  3. # 计算手牌属于哪种组合以及特征值
  4. def cal_max(cards):
  5.     color = [_ for _ in filter(None, re.split('[\dTJQKA ]', cards)[1:])]
  6.     value = [_ for _ in filter(None, re.split('[CDHS ]', cards)[:-1])]

  7.     for i in range(5):
  8.         if value[i] == 'T':
  9.             value[i] = 10
  10.         elif value[i] == 'J':
  11.             value[i] = 11
  12.         elif value[i] == 'Q':
  13.             value[i] = 12
  14.         elif value[i] == 'K':
  15.             value[i] = 13
  16.         elif value[i] == 'A':
  17.             value[i] = 14
  18.         else:
  19.             value[i] = int(value[i])
  20.     value.sort()
  21.     if len(set(color)) == 1:
  22.         # # Case 9: 同花顺
  23.         if len(set([int(value[i]) - int(value[i-1]) for i in range(1, 5)])) == 1:
  24.             return [9, value]
  25.         else:
  26.             # Case 6: 同花
  27.             return [6, value]
  28.     else:
  29.         single_values = []
  30.         single_counts = []
  31.         for each_value in set(value):
  32.             single_values.append(each_value)
  33.             single_counts.append(value.count(each_value))

  34.         # Case 8: 炸弹
  35.         if 4 in single_counts:
  36.             return [8, single_values[single_counts.index(4)]]

  37.         # Case 7: 三条加一对
  38.         elif 3 in single_counts and 2 in single_counts:
  39.             return [7, single_values[single_counts.index(3)]]

  40.         # Case 4: 三条
  41.         elif 3 in single_counts:
  42.             return [4, single_values[single_counts.index(3)]]

  43.         # Case 3: 两个对子
  44.         elif 2 in single_counts and single_counts.count(2) == 2:
  45.             tmp = []
  46.             for i in range(len(single_counts)):
  47.                 if single_counts[i] == 2:
  48.                     tmp.append(single_values[i])
  49.             tmp.sort()
  50.             return [3, tmp, single_values[single_counts.index(1)]]

  51.         # Case 2: 单个对子
  52.         elif 2 in single_counts:
  53.             max_value = single_values[single_counts.index(2)]
  54.             single_values.remove(max_value)
  55.             single_values.sort()
  56.             return [2, max_value, single_values]

  57.         # Case 5: 顺子
  58.         elif len(set([int(value[i]) - int(value[i-1]) for i in range(1, 5)])) == 1:
  59.             return [5, max(value)]

  60.         # Case 1: 单牌
  61.         else:
  62.             return [1, value]


  63. with open(r'C:\Users\wangyongzhao\Desktop\p054_poker.txt') as f:
  64.     cases = f.readlines()
  65.     total_games = len(cases)  # 总胜场计数
  66.     count1 = 0  # p1 胜场计数
  67.     count2 = 0  # p2 胜场计数
  68.     for each in cases:
  69.             p1 = cal_max(each.strip()[:14])
  70.             p2 = cal_max(each.strip()[15:])
  71.             if p1[0] > p2[0]:
  72.                 count1 += 1
  73.             elif p1[0] < p2[0]:
  74.                 count2 += 1
  75.             else:
  76.                 # 都是对子或者都是顺子,从第一结果看平局了, 分情况讨论
  77.                 # 第一种情况,都是单牌(从大到小逆序挨个作比较,有不同值就产生结果)
  78.                 if p1[0] == 1:
  79.                     for i in range(4, -1, -1):
  80.                         if p1[1][i] < p2[1][i]:
  81.                             count2 += 1
  82.                             break
  83.                         elif p1[1][i] > p2[1][i]:
  84.                             count1 += 1
  85.                             break
  86.                 # 第二种情况,都有对子(实际9个case都要分类讨论,但是file里只涉及这两种!)
  87.                 elif p1[0] == 2:
  88.                     if p1[1] > p2[1]:
  89.                         count1 += 1
  90.                     elif p1[1] < p2[1]:
  91.                         count2 += 1
  92.                     else:
  93.                         for i in range(2, -1, -1):
  94.                             if p1[2][i] < p2[2][i]:
  95.                                 count2 += 1
  96.                                 break
  97.                             elif p1[2][i] > p2[2][i]:
  98.                                 count1 += 1
  99.                                 break
  100.                 else:
  101.                     print("未分类平局对决", p1, "《--》", p2)
  102. print("总共进行了: {} 次比赛\nP1赢了: {} 次!\nP2赢了: {} 次!\n用时:{} 秒".format(total_games, count1, count2, time.process_time()))
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-11-21 09:33:37 | 显示全部楼层
  1. vm = {'T' : 10, 'J' : 11, 'Q' : 12, 'K' : 13, 'A' : 14}
  2. for i in range(2, 10):
  3.   vm[str(i)] = i
  4. sm = {'C' : 0, 'D' : 1, 'S' : 2, 'H' : 3}
  5. def fun(x):
  6.   v = [0] * 15
  7.   s = [0] * 4
  8.   for i in x:
  9.     v[vm[i[0]]] += 1
  10.     s[sm[i[1]]] += 1
  11.   r = [0] * 9
  12.   r[8] = max(map(lambda x: x[0] if x[1] != 0 else 0, enumerate(v)))
  13.   r[7] = max(map(lambda x: x[0] if x[1] == 2 else 0, enumerate(v)))
  14.   r[6] = r[7] if len(list(filter(lambda x: x == 2, v))) == 2 else 0
  15.   r[5] = max(map(lambda x: x[0] if x[1] == 3 else 0, enumerate(v)))
  16.   tmp = list(map(lambda x: 1 if x != 0 else 0, v))
  17.   r[4] = max(map(lambda x: x[0] if x[1] == 5 else 0,
  18.                  enumerate(map(lambda x: sum(tmp[x-5:x]), range(5, 15)), start = 1)))
  19.   r[3] = r[8] if len(list(filter(lambda x: x == 5, s))) == 1 else 0
  20.   r[2] = r[5] if r[5] != 0 and r[7] != 0 else 0
  21.   r[1] = max(map(lambda x: x[0] if x[1] == 4 else 0, enumerate(v)))
  22.   r[0] = r[4] if r[4] != 0 and r[3] != 0 else 0
  23.   return r

  24. f = open('54.txt', 'r')
  25. hand = list(map(lambda x: x.split(), filter(lambda x: len(x) != 0, f.read().split('\n'))))
  26. print(len(list(filter(lambda x: fun(x[:5]) > fun(x[5:]), hand))))
复制代码

https://github.com/devinizz/project_euler/blob/master/page02/54.py
持续更新中...
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-26 16:55:48 | 显示全部楼层
376

Process returned 0 (0x0)   execution time : 0.058 s
Press any key to continue.
十分赞同2#的看法……本题思维难度不大,但极为复杂,情况众多,很容易犯错
我想我的代码或许可以再优化些……
  1. #include<algorithm>
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<string>
  5. #include<cctype>
  6. #include<map>
  7. using namespace std;

  8. const int M = 1000;
  9. const string royal("TJQKA");
  10. const string STRAIGHT("A23456789TJQKA");
  11. string value[2],suit[2];
  12. bool cmp(char i,char j);

  13. int posi(char x){
  14.   for (int i = 0;i < 5;i++)
  15.     if (x == royal[i])  return i;
  16. }

  17. void erase_char(char c,string & s){
  18.   do{
  19.     s.erase(find(s.begin(),s.end(),c) );
  20.   }while(find(s.begin(),s.end(),c) != s.end() );
  21. }

  22. bool p1win(const string & s1,const string & s2){
  23.   for (int i = s1.length() - 1; i >= 0;i--){
  24.     if (s1[i] == s2[i]) continue;
  25.     if (!cmp(s1[i],s2[i]) )  return true;
  26.     if (cmp(s1[i],s2[i]) )  return false;
  27.   }
  28. }

  29. char dom(int p){
  30.   map<char,int> times;  char domin;
  31.   int mx = 0;

  32.   for (int i = 0;i < value[p].length();i++){
  33.     char t = value[p][i];

  34.     if (!times.count(t) )  times[t] = 1;
  35.     else times[t]++;
  36.   }
  37.   for (map<char,int>::iterator it = times.begin();it != times.end();++it)
  38.     if (it->second > mx)  {mx = it->second; domin = it->first;}

  39.   return domin;
  40. }

  41. bool cmp(char i,char j){
  42.   if (isdigit(i) && isdigit(j)) return i < j;

  43.   if (isdigit(i) && isalpha(j)) return true;
  44.   if (isdigit(j) && isalpha(i)) return false;

  45.   return posi(i) < posi(j);
  46. }

  47. bool is_straight(string & s){
  48.   sort(s.begin(),s.end(),cmp);

  49.   for (int i = 0;i < 10;i++)
  50.     if (s == STRAIGHT.substr(i,5)) return true;

  51.   return false;
  52. }

  53. bool isflush(string s){
  54.   for (int i = 0;i < s.length() - 1;i++)
  55.     if (s[i+1] != s[i]) return false;

  56.   return true;
  57. }

  58. int others(string s){
  59.   map<char,int> times;

  60.   for (int i = 0;i < s.length();i++){
  61.     char t = s[i];

  62.     if (!times.count(t) )  times[t] = 1;
  63.     else times[t]++;
  64.   }
  65.   int sz = times.size();
  66.   if (sz == 5)  return 0;
  67.   if (sz == 4)  return 1;
  68.   if (sz == 2)  {
  69.     for (map<char,int>::iterator it = times.begin();it != times.end();++it){
  70.       if (it->second == 4)  return 7;
  71.       if (it->second == 3)  return 6;
  72.     }
  73.   }
  74.   if (sz == 3)  {
  75.     for (map<char,int>::iterator it = times.begin();it != times.end();++it){
  76.       if (it->second == 2)  return 2;
  77.       if (it->second == 3)  return 3;
  78.     }
  79.   }
  80.   return -1;//error
  81. }

  82. int judge_type(int p){
  83.   bool f = isflush(suit[p]);
  84.   bool st = is_straight(value[p]);

  85.   if (f && st)  return 8;
  86.   if (!f && st) return 4;
  87.   if (f && !st) return 5;

  88.   return others(value[p]);

  89.   return -1;//error
  90. }
  91. /*  0:High Card         1:One Pair  2:Two Pairs
  92.     3:Three of a Kind   4:Straight  5:Flush
  93.     6:Full House        7:Four of a Kind
  94.     8:Straight Flush
  95. */
  96. void print(){
  97.   cout << value[0] << " " << value[1] << endl;
  98.   cout << suit[0] << " " << suit[1] << endl << endl;
  99. }

  100. void ini(){
  101.   for (int i = 0;i < 2;i++){
  102.     value[i].clear();
  103.     suit[i].clear();
  104.   }
  105. }

  106. int main(){
  107.   freopen("i.in","r",stdin);
  108.   int cnt = 0;

  109.   for (int r = 0;r < M;r++){
  110.     ini();

  111.     for (int i = 0;i < 2;i++){
  112.       for (int j = 0;j < 5;j++){
  113.         string s;
  114.         cin >> s;
  115.         value[i].push_back(s[0]);
  116.         suit[i].push_back(s[1]);
  117.       }
  118.     }
  119.     //print();

  120.     int p1 = judge_type(0),p2 = judge_type(1);//此后,点数序列有序
  121.     //cout << p1 << " " << p2 << endl;  cout << value[0] << " " << value[1] << endl;

  122.     if (p1 > p2) {cnt++;  continue;}
  123.     if (p1 == p2){
  124.       switch(p1){
  125.         case 0:
  126.         case 5: if (p1win(value[0],value[1]) )  cnt++;
  127.                 break;

  128.         case 4:
  129.         case 8: if (cmp(value[1][4],value[0][4]) )  cnt++;
  130.                 break;

  131.         case 1:
  132.         case 3: {
  133.           char c1 = dom(0),c2 = dom(1);
  134.           if (c1 == c2) {
  135.             string s1 = value[0],s2 = value[1];
  136.             erase_char(c1,s1);  sort(s1.begin(),s1.end(),cmp);
  137.             erase_char(c2,s2);  sort(s2.begin(),s2.end(),cmp);

  138.             if (p1win(s1,s2)) {cnt++; break;}
  139.           }
  140.           if (cmp(c2,c1) )   cnt++;
  141.           break;

  142.         }
  143.         case 6:
  144.         case 7: {
  145.           char c1 = dom(0),c2 = dom(1);
  146.             if (c1 == c2){
  147.               char d1,d2;
  148.               for (int i = 0;i < 5;i++){
  149.                 if (value[0][i] != c1) {d1 = value[0][i]; break;}
  150.                 if (value[1][i] != c2) {d2 = value[1][i]; break;}
  151.               }
  152.               if (cmp(d2,d1) )  {cnt++; break;}
  153.             }
  154.             if (cmp(c2,c1) )   cnt++;
  155.             break;

  156.         }
  157.         case 2: map<char,int> times[2];
  158.                 string mypair[2];
  159.                 char d[2];
  160.                 for (int i = 0;i < 2;i++){
  161.                   for (int j = 0;j < 5;j++){
  162.                     char t = value[i][j];

  163.                     if (!times[i].count(t) )  times[i][t] = 1;
  164.                     else times[i][t]++;

  165.                     if (times[i][t] == 2)  mypair[i].push_back(t);
  166.                   }
  167.                   for (map<char,int>::iterator it = times[i].begin();it != times[i].end();++it)
  168.                     if (it->second = 1)   {d[i] = it->first;  break;}

  169.                   sort(mypair[i].begin(),mypair[i].end(),cmp);
  170.                 }
  171.                 if (cmp(mypair[1][3],mypair[0][3]) )  {cnt++; break;}
  172.                 else if (mypair[1][3] == mypair[0][3]){
  173.                   if (cmp(mypair[1][0],mypair[0][0]) )  {cnt++; break;}
  174.                   else if(mypair[1][0] == mypair[0][0]){
  175.                     if (cmp(d[1],d[0]) )  {cnt++; break;}
  176.                   }
  177.                 }
  178.       }
  179.     }
  180.   }
  181.   cout << cnt << endl;
  182.   return 0;
  183. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-2-8 10:28:37 From FishC Mobile | 显示全部楼层
实 际 开 发 实 况
我连题目都看不懂
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-10-25 17:16:31 | 显示全部楼层
  1. import time as t
  2. import numpy as np

  3. start = t.perf_counter()


  4. def evaluate_cards(suits, values):
  5.     # Scores. Pair: 3; Three of a kind: 7; Straight: 8; Flush: 9; Four of a Kind: 11; Royal Flush: 18
  6.     cards_value = 0
  7.     set_values = set(values)
  8.     is_straight = True
  9.     if len(set(suits)) == 1:
  10.         cards_value += 9
  11.         if set_values == (8, 9, 10, 11, 12):
  12.             cards_value += 9

  13.     for value in range(4):
  14.         if not (values[value + 1] - values[value] == 1):
  15.             is_straight = False
  16.     if is_straight:
  17.         cards_value += 8

  18.     dict_cards = {value: values.count(value) for value in values}
  19.     pair_count, three_count, four_count = 0, 0, 0
  20.     for value in dict_cards:
  21.         if dict_cards[value] == 2:
  22.             pair_count += 1
  23.         elif dict_cards[value] == 3:
  24.             three_count += 1
  25.         elif dict_cards[value] == 4:
  26.             four_count += 1
  27.     cards_value += (pair_count * 3 + three_count * 7 + four_count * 11)

  28.     return cards_value, dict_cards


  29. def compare_cards(cards_list_1, cards_list_2):
  30.     cards_order = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
  31.     values_1, suits_1, values_2, suits_2 = [], [], [], []
  32.     for card in range(5):
  33.         values_1.append(cards_order.index(cards_list_1[card][0]))
  34.         suits_1.append(cards_list_1[card][1])
  35.         values_2.append(cards_order.index(cards_list_2[card][0]))
  36.         suits_2.append(cards_list_2[card][1])
  37.     values_1.sort()
  38.     values_2.sort()
  39.     cards_value_1, cards_dict_1 = evaluate_cards(suits_1, values_1)
  40.     cards_value_2, cards_dict_2 = evaluate_cards(suits_2, values_2)
  41.     if cards_value_1 > cards_value_2:
  42.         return True
  43.     elif cards_value_1 < cards_value_2:
  44.         return False
  45.     elif cards_value_1 == 17 or cards_value_1 == 9 or cards_value_1 == 8 or cards_value_1 == 0:
  46.         for max_value in range(-1, -6, -1):
  47.             if values_1[max_value] > values_2[max_value]:
  48.                 return True
  49.             elif values_1[max_value] < values_2[max_value]:
  50.                 return False
  51.     elif cards_value_1 == 3 or cards_value_1 == 6 or cards_value_1 == 7 or cards_value_1 == 10 or cards_value_1 == 11:
  52.         while True:
  53.             if max(cards_dict_1.values()) > 1:
  54.                 max_value_1 = max(cards_dict_1, key=lambda x: cards_dict_1[x])
  55.                 max_value_2 = max(cards_dict_2, key=lambda x: cards_dict_2[x])
  56.             else:
  57.                 max_value_1 = max(cards_dict_1)
  58.                 max_value_2 = max(cards_dict_2)
  59.             if max_value_1 > max_value_2:
  60.                 return True
  61.             elif max_value_1 < max_value_2:
  62.                 return False
  63.             else:
  64.                 cards_dict_1[max_value_1] = 0
  65.                 cards_dict_2[max_value_2] = 0


  66. hands = np.loadtxt('C:/Users/wuhw/Desktop/p054_poker.txt', dtype=str)
  67. count_1_win = 0
  68. for all_cards in hands:
  69.     cards_list = list(all_cards)
  70.     res = compare_cards(cards_list[:5], cards_list[5:])
  71.     if res:
  72.         count_1_win += 1

  73. print(count_1_win)
  74. print("It costs %f s" % (t.perf_counter() - start))
复制代码


376
It costs 0.038529 s
浪费一个小时做这个破题,我真的是个傻逼
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-28 19:53

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表