标签:style blog http color os io for art
昨天晚上写的,写了一个多小时,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 --复杂模拟,布布扣,bubuko.com
标签:style blog http color os io for art
原文地址:http://www.cnblogs.com/whatbeg/p/3896685.html