ZOJ 1111 Poker Hands --复杂模拟

昨天晚上写的,写了一个多小时,9000+B,居然1A了,爽。

题意:玩扑克,比大小。规则如下:

题意很简单,看过赌神的人都知道,每人手中5张排,比牌面大小,牌面由大到小分别是(这里花色无大小),级别从高到低依次为:
1.同花顺:牌面一样,只比较最大的看谁大,一样大则平手
2.四条:四个一样的,看这四个一样的中谁大谁赢
3.葫芦:三条+一对,看三条中谁的牌面大
4.同花:都是同花就按从大到小比较,看谁的更大
5.顺子:都是顺子看最大的谁大,一样则平手
6.三条:三条看三条中谁的牌面大
7.两对: 两对就看谁的对子大,都一样大比单牌
8.一对: 比对子,一样则比单牌
9.单排:按顺序比较大小,大者胜

知道规则了就搞就行了。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 100007

struct node
{
    int num,suit;
}a[7],b[7];
int BigstPair[2],SecondPair[2],Remain[2];  //7
int k[6][2];  //4
int m[5][2];  //8

int cmp(node ka,node kb)
{
    return ka.num < kb.num;
}

pair<int,int> solve(node a[],int tag)
{
    int i,j;
    sort(a,a+5,cmp);
    int level = 9;
    int val = 0;
    int flag = 0;
    for(i=1;i<5;i++)
    {
        if(a[i].suit != a[i-1].suit)
            break;
    }
    if(i == 5)
    {
        for(j=1;j<5;j++)
        {
            if(a[j].num != a[j-1].num+1)
                break;
        }
        if(j == 5)
            return make_pair(level,a[4].num);
    }
    //2
    level--;
    if((a[0].num == a[1].num && a[1].num == a[2].num && a[2].num == a[3].num)||(a[1].num == a[2].num && a[2].num == a[3].num && a[3].num == a[4].num))
    {
        if(a[3].num == a[4].num)
            return make_pair(level,a[4].num);
        else if(a[0].num == a[1].num)
            return make_pair(level,a[0].num);
    }
    //3
    level--;
    if(a[0].num == a[1].num && a[2].num == a[3].num && a[3].num == a[4].num)
        return make_pair(level,a[4].num);
    if(a[0].num == a[1].num && a[1].num == a[2].num && a[3].num == a[4].num)
        return make_pair(level,a[0].num);
    //4
    level--;
    if(a[0].suit == a[1].suit && a[1].suit == a[2].suit && a[2].suit == a[3].suit && a[3].suit == a[4].suit)
    {
        k[1][tag] = a[0].num;
        k[2][tag] = a[1].num;
        k[3][tag] = a[2].num;
        k[4][tag] = a[3].num;
        k[5][tag] = a[4].num;
        return make_pair(level,a[4].num);
    }
    //5
    level--;
    for(i=1;i<5;i++)
    {
        if(a[i].num != a[i-1].num+1)
            break;
    }
    if(i == 5)
        return make_pair(level,a[4].num);
    //6
    level--;
    int cnt = 1;
    for(i=4;i>=0;i--)
    {
        if(a[i].num == a[i+1].num)
        {
            cnt++;
            if(cnt >= 3)
                return make_pair(level,a[i].num);
        }
        else
            cnt = 1;
    }
    //7
    level--;
    if(a[0].num == a[1].num && a[3].num == a[4].num)
    {
        BigstPair[tag] = a[3].num;
        SecondPair[tag] = a[1].num;
        Remain[tag] = a[2].num;
        return make_pair(level,BigstPair[tag]);
    }
    if(a[0].num == a[1].num && a[2].num == a[3].num)
    {
        BigstPair[tag] = a[3].num;
        SecondPair[tag] = a[1].num;
        Remain[tag] = a[4].num;
        return make_pair(level,BigstPair[tag]);
    }
    if(a[1].num == a[2].num && a[3].num == a[4].num)
    {
        BigstPair[tag] = a[3].num;
        SecondPair[tag] = a[1].num;
        Remain[tag] = a[0].num;
        return make_pair(level,BigstPair[tag]);
    }
    //8
    level--;
    if(a[3].num == a[4].num)
    {
        m[1][tag] = a[0].num;
        m[2][tag] = a[1].num;
        m[3][tag] = a[2].num;
        m[4][tag] = a[3].num;
        return make_pair(level,m[4][tag]);
    }
    if(a[2].num == a[3].num)
    {
        m[1][tag] = a[0].num;
        m[2][tag] = a[1].num;
        m[3][tag] = a[4].num;
        m[4][tag] = a[3].num;
        return make_pair(level,m[4][tag]);
    }
    if(a[1].num == a[2].num)
    {
        m[1][tag] = a[0].num;
        m[2][tag] = a[3].num;
        m[3][tag] = a[4].num;
        m[4][tag] = a[2].num;
        return make_pair(level,m[4][tag]);
    }
    if(a[0].num == a[1].num)
    {
        m[1][tag] = a[2].num;
        m[2][tag] = a[3].num;
        m[3][tag] = a[4].num;
        m[4][tag] = a[0].num;
        return make_pair(level,m[4][tag]);
    }
    //9 High Cards
    level--;
    k[1][tag] = a[0].num;
    k[2][tag] = a[1].num;
    k[3][tag] = a[2].num;
    k[4][tag] = a[3].num;
    k[5][tag] = a[4].num;
    return make_pair(level,k[5][tag]);
}

int compare(pair<int,int> ka,pair<int,int> kb)
{
    if(ka.first == kb.first)
    {
        if(ka.first == 6 || ka.first == 1)  //flush or high card
        {
            if(k[5][0] == k[5][1])
            {
                if(k[4][0] == k[4][1])
                {
                    if(k[3][0] == k[3][1])
                    {
                        if(k[2][0] == k[2][1])
                        {
                            if(k[1][0] == k[1][1])
                                return 0;
                            else if(k[1][0] > k[1][1])
                                return 1;
                            else
                                return -1;
                        }
                        else if(k[2][0] > k[2][1])
                            return 1;
                        else
                            return -1;
                    }
                    else if(k[3][0] > k[3][1])
                        return 1;
                    else
                        return -1;
                }
                else if(k[4][0] > k[4][1])
                    return 1;
                else
                    return -1;
            }
            else if(k[5][0] > k[5][1])
                return 1;
            else
                return -1;
        }
        else if(ka.first == 3)  //two pair
        {
            if(BigstPair[0] == BigstPair[1])
            {
                if(SecondPair[0] == SecondPair[1])
                {
                    if(Remain[0] == Remain[1])
                        return 0;
                    else if(Remain[0] > Remain[1])
                        return 1;
                    else
                        return -1;
                }
                else if(SecondPair[0] > SecondPair[1])
                    return 1;
                else
                    return -1;
            }
            else if(BigstPair[0] > BigstPair[1])
                return 1;
            else
                return -1;
        }
        else if(ka.first == 2)  //pair
        {
            if(m[4][0] == m[4][1])
            {
                if(m[3][0] == m[3][1])
                {
                    if(m[2][0] == m[2][1])
                    {
                        if(m[1][0] == m[1][1])
                            return 0;
                        else if(m[1][0] > m[1][1])
                            return 1;
                        else
                            return -1;
                    }
                    else if(m[2][0] > m[2][1])
                        return 1;
                    else
                        return -1;
                }
                else if(m[3][0] > m[3][1])
                    return 1;
                else
                    return -1;
            }
            else if(m[4][0] > m[4][1])
                return 1;
            else
                return -1;
        }
        else
        {
            if(ka.second == kb.second)
                return 0;
            else if(ka.second > kb.second)
                return 1;
            else
                return 0;
        }
    }
    else
    {
        if(ka.first > kb.first)
            return 1;
        else if(ka.first < kb.first)
            return -1;
    }
}

int main()
{
    int i,j;
    char ss[12][3];
    while(scanf("%s",ss[0])!=EOF)
    {
        for(i=1;i<10;i++)
            scanf("%s",ss[i]);
        for(i=0;i<5;i++)
        {
            char pre = ss[i][0];
            char back = ss[i][1];
            if(pre >= ‘2‘ && pre <= ‘9‘)
                a[i].num = pre-‘0‘;
            else if(pre == ‘T‘)
                a[i].num = 10;
            else if(pre == ‘J‘)
                a[i].num = 11;
            else if(pre == ‘Q‘)
                a[i].num = 12;
            else if(pre == ‘K‘)
                a[i].num = 13;
            else if(pre == ‘A‘)
                a[i].num = 14;
            // 0:C  1:D  2:H  3:S
            if(back == ‘C‘)
                a[i].suit = 0;
            else if(back == ‘D‘)
                a[i].suit = 1;
            else if(back == ‘H‘)
                a[i].suit = 2;
            else
                a[i].suit = 3;
        }
        for(i=5;i<10;i++)
        {
            char pre = ss[i][0];
            char back = ss[i][1];
            if(pre >= ‘2‘ && pre <= ‘9‘)
                b[i-5].num = pre-‘0‘;
            else if(pre == ‘T‘)
                b[i-5].num = 10;
            else if(pre == ‘J‘)
                b[i-5].num = 11;
            else if(pre == ‘Q‘)
                b[i-5].num = 12;
            else if(pre == ‘K‘)
                b[i-5].num = 13;
            else if(pre == ‘A‘)
                b[i-5].num = 14;
            // 0:C  1:D  2:H  3:S
            if(back == ‘C‘)
                b[i-5].suit = 0;
            else if(back == ‘D‘)
                b[i-5].suit = 1;
            else if(back == ‘H‘)
                b[i-5].suit = 2;
            else
                b[i-5].suit = 3;
        }
        int res = compare(solve(a,0),solve(b,1));
        if(res > 0)
            puts("Black wins.");
        else if(res == 0)
            puts("Tie.");
        else
            puts("White wins.");
    }
    return 0;
}

ZOJ 1111 Poker Hands --复杂模拟

时间: 2024-08-03 21:10:39

ZOJ 1111 Poker Hands --复杂模拟的相关文章

ZOJ 1111 Poker Hands

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1111 A poker hand consists of 5 cards dealt from the deck. Poker hands are ranked by the following partial order from lowest to highest High Card. Hands which do not fit any higher cat

1111实验二 作业调度模拟实验

实验二.作业调度模拟实验 物联网工程 张怡 201306104149 一.实验目的  (1)加深对作业调度算法的理解: (2)进行程序设计的训练. 二.实验内容和要求 1.至少用三种调度算法: 1) 采用先来先服务(FCFS)调度算法,即按作业到达的先后次序进行调度.总是首先调度在系统中等待时间最长的作业. 2) 短作业优先 (SJF) 调度算法,优先调度要求运行时间最短的作业. 3) 响应比高者优先(HRRN)调度算法,为每个作业设置一个优先权(响应比),调度之前先计算各作业的优先权,优先数高

zoj 3818 Pretty Poem (模拟)

ZOJ Problem Set - 3818 Pretty Poem Time Limit: 2 Seconds      Memory Limit: 65536 KB Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM

ZOJ 3818 Pretty Poem (暴力模拟 string(substr))

Pretty Poem Time Limit: 2 Seconds      Memory Limit: 65536 KB Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM-ICPC contestants can e

zoj 3314 CAPTCHA(纯模拟)

题目 有些人用深搜写的,当然我这弱弱的,只理解纯模拟... 纯模拟,第一次写了那么长的代码,我自己也是够坚韧不拔的,,,,必须留念啊!!! 注意,G包含C,E包含L,R包含P,(照图说O应该不包含C,但是不排除掉这种情况,就wa掉了,所以要排除O包含C的情况..) #include<stdio.h> #include<string.h> int n,m; char s2[330][330]; int vis[30]; void fun(){ //a if(vis[0]==0){ f

ZOJ 3326 An Awful Problem 模拟

只有在 Month 和 Day 都为素数的时候才能得到糖 那就模拟一遍时间即可. //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream> #include <cstring> #include <cmath> #include <sta

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker(gcd模拟)

Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can

ZOJ 2954 Hanoi Tower(模拟啊 )

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1953 You all must know the puzzle named "The Towers of Hanoi". The puzzle has three pegs (peg 1, peg 2 and peg 3) and N disks of different radii. Initially all disks are located on

[ZOJ 1006] Do the Untwist (模拟实现解密)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6 题目大意:给你加密方式,请你求出解密. 直接逆运算搞,用到同余定理 1 #include <cstdio> 2 #include <cstdlib> 3 #include <string> 4 #include <iostream> 5 #include <cstring> 6 #include <algori