Time limit: 6000ms
Single point time limit: 1000ms
Memory Limit: 256MB
Describe
You play stud in the casino, have been issued 4 cards, now you want to know the next card issued after you get the probability of a straight son how much?
Suppose the casino uses a deck of cards, four suits of a, 2, 3 、...、 J, Q, K a total of 52, this deck only sent you 4, you left a card from the remaining 48 arbitrarily take out a card.
Shun Zi refers to a continuous number of five cards, including 10, J, Q, K, a such card type (does not contain the same flower, that is, the five cards constituting the CIS can not be the same). See also: Https://zh.wikipedia.org/wiki/%E6%92%B2%E5%85%8B%E7%89%8C%E5%9E%8B#.E7.89.8C.E5.9E.8B
Input
A line of four strings separated by a space of 2 or 3, XY, representing the cards in your hand.
X is 2~10, J, Q, K, a in one, indicating the number of points, Y is S, H, C, D, respectively, for spades, hearts, clubs and squares.
Output
One line of a fraction represents the probability, note that your score needs to be the simplest fraction, if the answer is 0 output 0/1.
Sample input
10S JS QS KD
Sample output
1/6
The topic is a simulation that only uses violence to enumerate each card.
The final answer GCD the number of conventions after processing the output.
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<algorithm>#include<Set>#include<map>#include<queue>#include<string>#defineLL Long Longusing namespacestd;structcard{intnum; Charkind;};BOOLCMP (card A, card b) {returnA.num <B.num;}structnode{Card card[5];} my;intans;//GCD//Beg Greatest common divisor//O (LOGN)intgcdintAintb) { if(b = =0) returnA; Else returnGCD (b, a%b);}BOOLinput () {Charstr[5]; for(inti =0; I <4; ++i) {if(SCANF ("%s", str) = =EOF)return false; if(strlen (str) = =2) { if('2'<= str[0] && str[0] <='9') My.card[i].num= str[0] -'0'; Else if(str[0] =='A') My.card[i].num=1; Else if(str[0] =='J') My.card[i].num= One; Else if(str[0] =='Q') My.card[i].num= A; Else if(str[0] =='K') My.card[i].num= -; My.card[i].kind= str[1]; } Else{my.card[i].num=Ten; My.card[i].kind= str[2]; } } return true;}BOOLjudge (Node T) {if(t.card[0].kind = = t.card[1].kind &&t.card[1].kind = = t.card[2].kind &&t.card[2].kind = = t.card[3].kind &&t.card[3].kind = = t.card[4].kind)return false; Sort (T.card, T.card+5, CMP); if(t.card[0].num+1= = t.card[1].num &&t.card[1].num+1= = t.card[2].num &&t.card[2].num+1= = t.card[3].num &&t.card[3].num+1= = t.card[4].num)return true; if(t.card[0].num = =1&&t.card[1].num+1= = t.card[2].num &&t.card[2].num+1= = t.card[3].num &&t.card[3].num+1= = t.card[4].num &&t.card[4].num = = -) return true; return false;}voidWork () {ans=0; for(inti =1; I <= -; ++i) {my.card[4].num =i; my.card[4].kind ='S'; Ans+=judge (my); my.card[4].kind ='H'; Ans+=judge (my); my.card[4].kind ='C'; Ans+=judge (my); my.card[4].kind ='D'; Ans+=judge (my); } intD = gcd (ans, -); if(ans = =0) printf ("0/1\n"); Elseprintf ("%d/%d\n", ANS/D, -/d);}intMain () {//freopen ("test.in", "R", stdin); while(Input ()) {work (); } return 0;}
ACM Learning Journey-hihocoder 1177 CIS (simulation && sequencing && GCD) (Hihocoder Challenge 12)