zoukankan      html  css  js  c++  java
  • 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
    /**
              题意:如题给出了4张扑克  然后求得到顺子的概率
              做法:模拟  首先1,2,3,4,5不算顺子,然后题中的要求是不能是同花
                        然后开始模拟
    **/
    #include <iostream>
    #include <string.h>
    #include <cmath>
    #include <stdio.h>
    #include <algorithm>
    #include <queue>
    #include <vector>
    using namespace std;
    char ch[10][10];
    int mmap[10];
    int main()
    {
    //#ifndef ONLINE_JUDGE
    //    freopen("in.txt","r",stdin);
    //#endif // ONLINE_JUDGE
        while(~scanf("%s %s %s %s",ch[0],ch[1],ch[2],ch[3]))
        {
            int res = 0,cet = 0;
            bool prime = true;
            for(int i=0; i<4; i++)
            {
                int len = strlen(ch[i]);
                int tt = 0;
                for(int j=0; j<len; j++)
                {
                    if(isdigit(ch[i][j]))
                    {
                        tt = tt * 10 + (ch[i][j] -'0');
                    }
                }
                if(ch[i][0] == 'A') tt = 14;
                if(ch[i][0] == 'J') tt = 11;
                if(ch[i][0] == 'Q') tt = 12;
                if(ch[i][0] == 'K') tt = 13;
                mmap[i] = tt;
                if(ch[i][len-1]  == 'S') res = 1;
                if(ch[i][len-1] == 'H') res = 2;
                if(ch[i][len-1] == 'C') res = 3;
                if(ch[i][len-1] == 'D') res = 4;
                if(i == 0)
                {
                    cet = res;
                }
                if(res != cet)
                {
                    prime = false;
                }
            }
            sort(mmap,mmap+4);
            int flag = 0;
            bool ok = true;
            for(int i=1; i<4; i++)
            {
                if(mmap[i] - mmap[i-1] == 1) continue;
                else if(mmap[i]- mmap[i-1] == 2)
                {
                    if(!flag) flag = i;
                    else  ok = false;
                }
                else ok = false;
            }
            if(ok == false)
            {
                printf("0/1");
            }
            else
            {
                if(flag)  ///在中间
                {
                    if(prime) printf("1/16");
                    else printf("1/12");
                }
                else
                {
                    if(!prime)
                    {
                        if(mmap[0] == 2 || mmap[3] == 14) printf("1/12");
                        else printf("1/6");
                                            }
                                            else
                                            {
                                                      if(mmap[0] == 2 || mmap[3] == 14) printf("1/16");
                                                      else printf("1/8");
                                            }
                }
            }
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    15 手写数字识别-小数据集
    14 深度学习-卷积
    13-垃圾邮件分类2
    12.朴素贝叶斯-垃圾邮件分类
    11.分类与监督学习,朴素贝叶斯分类算法
    9、主成分分析
    7.逻辑回归实践
    8.特征选择,过滤式
    6.逻辑回归
    5.线性回归算法
  • 原文地址:https://www.cnblogs.com/chenyang920/p/4596856.html
Copyright © 2011-2022 走看看