题目:手里有五张牌,桌上有一堆牌(五张)。你能够弃掉手中的k张牌,然后从牌堆中取最上面的k个。

比較规则例如以下:(按优先级排序)

1.straight-flush:同花顺。牌面为T(10) - A,这里不论花色是否同样;

2.four-of-a-kind:四条,牌面有4个同样的值。

3.full-house:船牌,牌面有3个同样值,剩下2个也同样值。

4.flush:同花,五张牌的花色同样,不是同花顺;

5.straight:顺子。五张牌的值连续,A能够作为1也能够作为14;

6.three-of-a-kind:三条,牌面有3个同样的值;

7.two-pairs:两对。牌面有2个对子。

8.one-pair:一对,牌面有一个对子,即2个同值;

9.highest-card:大牌,没有以上牌型。

分析:搜索、枚举。枚举换牌数从0-5的每种情况,推断,取出优先值最高的就可以。

说明:读题是重点。

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio> #define min(x,y) ((x)<(y)? (x):(y)) using namespace std; char temp[5][3];
char card[10][3];
int maps[5][13]; char output[11][20] = {
"","straight-flush","four-of-a-kind",
"full-house","flush","straight","three-of-a-kind",
"two-pairs","one-pair","highest-card",""}; int value( char ch )
{
if ( ch == 'T' ) return 9;
if ( ch == 'J' ) return 10;
if ( ch == 'Q' ) return 11;
if ( ch == 'K' ) return 12;
if ( ch == 'A' ) return 0;
return ch - '1';
} int color( char ch )
{
if ( ch == 'S' ) return 0;
if ( ch == 'H' ) return 1;
if ( ch == 'D' ) return 2;
if ( ch == 'C' ) return 3;
} int tests()
{
//royal-flush | straight-flush
for ( int i = 0 ; i < 5 ; ++ i )
if ( maps[i][0]&maps[i][9]&maps[i][10]&maps[i][11]&maps[i][12] )
return 1;
//four-of-a-kind
for ( int i = 0 ; i < 13 ; ++ i )
if ( maps[4][i] == 4 ) return 2;
//full-house
int three = 0,two = 0;
for ( int i = 0 ; i < 13 ; ++ i ) {
if ( maps[4][i] == 2 ) two ++;
if ( maps[4][i] == 3 ) three ++;
}
if ( two && three ) return 3;
//flush
for ( int i = 0 ; i < 4 ; ++ i ) {
int count = 0;
for ( int j = 0 ; j < 13 ; ++ j )
count += maps[i][j];
if ( count >= 5 ) return 4;
}
//straight
for ( int i = 0 ; i < 10 ; ++ i )
if ( maps[4][i]&maps[4][i+1]&maps[4][i+2]&maps[4][i+3]&maps[4][(i+4)%13] )
return 5;
//three-of-a-kind
if ( three ) return 6;
//two-pairs
if ( two > 1 ) return 7;
//one-pair
if ( two ) return 8;
return 9;
} void change()
{
for ( int i = 0 ; i < 5 ; ++ i )
strcpy(temp[i],card[i+5]);
memset( maps, 0, sizeof(maps) );
for ( int i = 0 ; i < 5 ; ++ i ) {
maps[color(temp[i][1])][value(temp[i][0])] = 1;
maps[4][value(temp[i][0])] ++;
}
int Min = tests(); for ( int k = 1 ; k <= 5 ; ++ k ) {
int xx,yy,comb = (1<<k)-1;
while ( comb < 32 ) {
// 计算当前状态相应的集合
int j = 0,count = 0,move = 5;
do {
if ( (1<<j)&comb )
strcpy(temp[count ++],card[j]);
j ++;
}while ( j < 5 ); while ( count < 5 )
strcpy(temp[count ++],card[move ++]); memset( maps, 0, sizeof(maps) );
for ( int i = 0 ; i < 5 ; ++ i ) {
maps[color(temp[i][1])][value(temp[i][0])] = 1;
maps[4][value(temp[i][0])] ++;
} Min = min(Min,tests());
// 位运算计算下一组合
xx = comb&-comb,yy = comb+xx;
comb = ((comb&~yy)/xx>>1)|yy;
}
}
printf("%s\n",output[Min]);
} int main()
{
while ( ~scanf("%s",card[0]) ) {
for ( int i = 1 ; i < 10 ; ++ i )
scanf("%s",card[i]); printf("Hand: ");
for ( int i = 0 ; i < 5 ; ++ i )
printf("%s ",card[i]);
printf("Deck: ");
for ( int i = 5 ; i < 10 ; ++ i )
printf("%s ",card[i]);
printf("Best hand: ");
change();
}
return 0;
}

UVa 131 - The Psychic Poker Player的更多相关文章

  1. uva131 The Psychic Poker Player

    The Psychic Poker Player Time Limit: 3000MS     64bit IO Format: %lld & %llu Description In 5-ca ...

  2. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  3. 备战NOIP每周写题记录(一)···不间断更新

    ※Recorded By ksq2013 //其实这段时间写的题远远大于这篇博文中的内容,只不过那些数以百记的基础题目实在没必要写在blog上; ※week one 2016.7.18 Monday ...

  4. [IOS] Storyboard全解析-第一部分

    (Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果,我贴上本教程所完成的Storyboard的截图: 现在,你就可以清楚的看到这 ...

  5. iOS Storyboard全解析

    来源:http://iaiai.iteye.com/blog/1493956 Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果, ...

  6. iOS Storyboard 的基本用法

    (Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果,我贴上本教程所完成的Storyboard的截图:  现 在,你就可以清楚的看 ...

  7. Java-->发牌流程修改版

    --> 这一次要封装得狠一点... package com.xm.ddz; // 每一张牌的属性 public class Card { private String flowerColor; ...

  8. 最新iOS 6 in Xcode4.5新特性——Storyboard和属性自动绑定

    最新iOS 6 in Xcode4.5新特性编程之二(上)——Storyboard和属性自动绑定 从Xcode 4.3开始,Storyboard 就是iOS 5和iOS 6中令人兴奋的一个新特性,他将 ...

  9. java练习:质数,匿名内部类创建接口,抽象类派生子类,画圆,字节截取字符串,数字变钱币,五子棋,梭哈

    java学习-质数的孤独 正在看质数的孤独,,,于是写了一个练习代码,输出1-100之间的质数 代码比较烂.待完善吧. 这里用到了continue和break,continue指结束当前轮次循环,跳入 ...

随机推荐

  1. poj2750Potted Flower (线段树)

    http://poj.org/problem?id=2750 之前做过类似的题 把一段的左连续最大.最小 右连续最大及最小及中间的连续更新出 就可以算出这段最大的连续和 注意不能全部加上 加上一特判 ...

  2. autofac 学习记录

    builder.RegisterModule(new ConfigurationSettingsReader()); 需要注册上面一句才能读到.config里的节点,xml配置方式如下 <con ...

  3. 深入理解Java虚拟机 - Java体系

    使用JAVA已经快三年了,但说来惭愧,一直以来认为Java就是Java语言本身,最多再包括一个JVM,对于整个Java的体系结构还是不甚明了,现在有时间把<深入理解Java虚拟机>这本书读 ...

  4. BZOJ_1021_[SHOI2008]_Debt循环的债务_(DP)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1021 三个人相互欠钱,给出他们每个人各种面额的钞票各有多少张,求最少需要传递多少张钞票才能把账 ...

  5. apache开源项目--Apache Drill

    为了帮助企业用户寻找更为有效.加快Hadoop数据查询的方法,Apache 软件基金会发起了一项名为“Drill”的开源项目.Apache Drill 实现了 Google's Dremel. Apa ...

  6. 百度UEditor编辑器使用教程与使用方法

    我们在做网站的时候,网站后台系统一般都会用到web编辑器,今天笔者就给大家推荐一款百度UEditor编辑器.关于这款百度UEditor编辑器官网上也有简单的教程,不过看着比较费劲,今天笔者就跟大家分享 ...

  7. Mtom Encoding in WCF

    http://www.codeproject.com/Articles/632101/Mtom-Encoding-in-WCF http://msdn.microsoft.com/zh-cn/libr ...

  8. HDU 5634 Rikka with Phi 线段树

    题意:bc round 73 div1 D 中文题面 分析:注意到10^7之内的数最多phi O(log(n))次就会变成1, 因此可以考虑把一段相同的不为1的数缩成一个点,用平衡树来维护. 每次求p ...

  9. 刷票 变 IP

    刷票 变 IP

  10. 跨平台的游戏客户端Socket封装,调整

    原文链接:http://www.cnblogs.com/lancidie/archive/2013/04/13/3019359.html 头文件: #pragma once #ifdef WIN32 ...