Hihocoder 顺子

#1177 : 顺子

时间限制: 6000ms
单点时限: 1000ms
内存限制: 256MB

描述

你在赌场里玩梭哈,已经被发了4张牌,现在你想要知道发下一张牌后你得到顺子的概率是多少?

假定赌场使用的是一副牌,四种花色的A、2、3、...、J、Q、K共52张,这副牌只发给你了4张,你的剩下一张牌从剩下48张中任意取出一张。

顺子指的是点数连续的五张牌,包括10、J、Q、K、A这种牌型(不包含同花顺,即构成顺子的五张牌花色不能相同)。参见:https://zh.wikipedia.org/wiki/%E6%92%B2%E5%85%8B%E7%89%8C%E5%9E%8B#.E7.89.8C.E5.9E.8B

输入

一行四个被空格隔开的长度为2或3的字符串,XY,表示你手里的牌。

X为2~10、J、Q、K、A中一个,表示点数,Y为S、H、C、D分别表示黑桃、红心、梅花和方块。

输出

一行一个分数表示概率,注意你的分数需为最简分数,若答案为0输出0/1。

样例输入
10S JS QS KD
样例输出
1/6
#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;
#define maxn 100

int gcd(int a, int b)
{
    return b==0 ? a : gcd(b, a%b);
}

struct Puke
{
    int val;
    int cor;
} P[maxn], T[maxn];

int cmp(const Puke a, const Puke b)
{
    return a.val < b.val;
}

string S;

int color(char ch)
{
    if(ch == 'S') return 1;
    if(ch == 'H') return 2;
    if(ch == 'C') return 3;
    if(ch == 'D') return 4;
}

void predo(string s, int i)
{
    if(s[0] == '1') P[i].val = 10;
    else if(s[0] == 'J') P[i].val = 11;
    else if(s[0] == 'Q') P[i].val = 12;
    else if(s[0] == 'K') P[i].val = 13;
    else if(s[0] == 'A') P[i].val = 14;
    else P[i].val = s[0] - '0';

    if(s[0] == '1')
        P[i].cor = color(s[2]);
    else P[i].cor = color(s[1]);
}

void read()
{
    for(int i=0; i<4; i++)
    {
        cin>>S;
        predo(S, i);
//        cout<<P[i].val<<"  "<<P[i].cor<<endl;
    }
}

void solve()
{
    int ans = 0;
    for(int i=2; i<=14; i++)
        for(int j=1; j<=4; j++)
        {
            for(int i=0; i<4; i++)
                T[i] = P[i];
            T[4] = Puke {i, j};
            sort(T, T+5, cmp);
//
//            for(int k=0; k<5; k++)
//            cout<<T[k].val<<" "<<T[k].cor<<"     ";
//            cout<<endl<<endl;

            bool flag = true;
            bool same = true;
            for(int i=0; i<4; i++)
            {
                if(T[i].val+1 != T[i+1].val) flag = false;
                if(T[i].cor != T[i+1].cor) same = false;
            }

            if(same) flag = false;
            if(flag) ans += 1;
        }
        //cout<<ans<<endl;

    int tmp = gcd(48, ans);
    printf("%d/%d", ans/tmp, 48/tmp);
}

int main()
{
    freopen("1.in.txt", "r", stdin);
    freopen("1.out.txt", "w", stdout);
    read();
    solve();
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值