UVa 131 - The Psychic Poker Player
题目:手里有五张牌,桌上有一堆牌(五张)。你能够弃掉手中的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的更多相关文章
- uva131 The Psychic Poker Player
The Psychic Poker Player Time Limit: 3000MS 64bit IO Format: %lld & %llu Description In 5-ca ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 备战NOIP每周写题记录(一)···不间断更新
※Recorded By ksq2013 //其实这段时间写的题远远大于这篇博文中的内容,只不过那些数以百记的基础题目实在没必要写在blog上; ※week one 2016.7.18 Monday ...
- [IOS] Storyboard全解析-第一部分
(Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果,我贴上本教程所完成的Storyboard的截图: 现在,你就可以清楚的看到这 ...
- iOS Storyboard全解析
来源:http://iaiai.iteye.com/blog/1493956 Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果, ...
- iOS Storyboard 的基本用法
(Storyboard)是一个能够节省你很多设计手机App界面时间的新特性,下面,为了简明的说明Storyboard的效果,我贴上本教程所完成的Storyboard的截图: 现 在,你就可以清楚的看 ...
- Java-->发牌流程修改版
--> 这一次要封装得狠一点... package com.xm.ddz; // 每一张牌的属性 public class Card { private String flowerColor; ...
- 最新iOS 6 in Xcode4.5新特性——Storyboard和属性自动绑定
最新iOS 6 in Xcode4.5新特性编程之二(上)——Storyboard和属性自动绑定 从Xcode 4.3开始,Storyboard 就是iOS 5和iOS 6中令人兴奋的一个新特性,他将 ...
- java练习:质数,匿名内部类创建接口,抽象类派生子类,画圆,字节截取字符串,数字变钱币,五子棋,梭哈
java学习-质数的孤独 正在看质数的孤独,,,于是写了一个练习代码,输出1-100之间的质数 代码比较烂.待完善吧. 这里用到了continue和break,continue指结束当前轮次循环,跳入 ...
随机推荐
- mysql_insert_id 为什么会返回空值
如果同时打开了一个以上的数据库资源,如果其中一个资源,没有使用insert语句或没有auto_increment类型的数据,或返回结果恰好为空值时,会导致mysql_insert_id()返回空值. ...
- process thread Fiber(linux)
http://blog.chinaunix.net/uid-21084809-id-2215376.html Processes, kernel threads, user threads, and ...
- 从ramdisk根文件系统启动Linux成功,及使用initramfs启动linux
下面两篇文章是ARM9论坛上的讲解ramdisk文件系统的很不错的文章 今天做了个试验,让Linux2.6.29.4从ramdisk根文件系统启动成功,总结一下. 其中涉及的内容较多,很多东西不再详述 ...
- (转载)php如何判断IP为有效IP地址
(转载)http://www.kuitao8.com/20130918/1376.shtml 多数人看到这篇日志,第一印象肯定是以为是要讲如何通过正则表达式来判断. 非也,在php5.2.0之后,有专 ...
- mycat分布式mysql中间件(数据库切分概述)[转]
mysql数据库切分 前言 通 过MySQLReplication功能所实现的扩展总是会受到数据库大小的限制,一旦数据库过于庞大,尤其是当写入过于频繁,很难由一台主机支撑的时 候,我们还是会面临到扩展 ...
- POJ3241 Object Clustering 曼哈顿最小生成树
题意:转换一下就是求曼哈顿最小生成树的第n-k条边 参考:莫涛大神的论文<平面点曼哈顿最小生成树> /* Problem: 3241 User: 96655 Memory: 920K Ti ...
- lightoj 1014
判断到根号n即可,另外使用dfs输出,不需要另开数组再排序. #include<cmath> #include<cstdio> int P, L, len, cnt; void ...
- 魅族MX2代理设置
魅族MX2买了快2年了,今天才知道有这个功能,唉 连接一个无线网络,比如我的centos 长按网络名字 选代理设置,设置自己的代理,再也不用SS 或 VPN 的android端了,老是提示ROOT权限 ...
- 【原】Storm 消息处理保障机制
Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...
- 将Magento后台汉化的方法
方法一: 打开/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php文件, 找到几个用来显示的代码,替换成 ...