文章
1
粉丝
0
获赞
25
访问
203
首先需要将牌面字符串映射为可比较的数值:3最小,赋值为1;2最大,赋值为13;中间按扑克牌规则递增
对三张牌排序后(从小到大),可以判断牌型:
豹子:三张牌相等
对子:两张相等(可能是前两张相等或后两张相等)
散牌:三张牌各不相同
为了高效比较,将多张牌的信息编码到一个整数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;
...
登录后发布评论
暂无评论,来抢沙发