文章

1

粉丝

0

获赞

25

访问

203

头像
小花狮的扑克 题解:
P5345 华东师范大学2025年机试题
发布于2026年3月13日 10:05
阅读数 203

解题思路

1. 牌面映射

首先需要将牌面字符串映射为可比较的数值:3最小,赋值为1;2最大,赋值为13;中间按扑克牌规则递增

2. 牌型判断

对三张牌排序后(从小到大),可以判断牌型:

  • 豹子:三张牌相等

  • 对子:两张相等(可能是前两张相等或后两张相等)

  • 散牌:三张牌各不相同

3. 分数编码

为了高效比较,将多张牌的信息编码到一个整数score中(使得不同牌型的分数区间分离,同牌型内可以精准比较大小):

  • 豹子点数 × 100

    • 例如:三张7 → 7×100 = 700

  • 对子对子点数 × 100 + 单牌点数

    • 例如:对5带8 → 5×100 + 8 = 508(对子可能在前两张或后两张,但编码方式相同)

  • 散牌最大牌 × 10000 + 中间牌 × 100 + 最小牌

    • 例如:A、10、5 → 12×10000 + 8×100 + 3 = 120803

!!最后一定要用'\n'换行,不然会超时。




#include<bits/stdc++.h>
using namespace std;

struct Person{
	string name;
	int type;//1-散牌,2-对子,3-豹子
	int score;
};

bool cmp(const Person &per1,const Person &per2){ // 优先级比较
	if(per1.type!=per2.type){
		return per1.type>per2.type;
	}else if(per1.score!=per2.score){
		return per1.score>per2.score;
	}else{
		return per1.name<per2.name;
...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发