2019icpc Shenyang network game H. Texas hold'em Poker (analog)

Analog wrote more cumbersome, too time-consuming, wrote more than one hour (the race -course sake )

Meaning of the title is very long, but read very clear, there are n individuals, each five hand, according to the rules of Texas Hold'em than the size, press the same name lexicographical output

Title simplified rule, we removed the suit, and the remaining single original ordering rule and then into a single summing over all individual and then compare the size of the

In all card type, the number of comparisons needed most is Two Pairs: 2 Dui same hand, if the two are Two Pairs, then the first, if larger than the same pair of big pair, is relatively small pair, if the same pair of small, remaining single comparator.

It can be concluded that only requires at least four rank all the cards will be able to type the size of the sort.

A structure may be used for each sub-band cards have four priority rank, each reading a card type according to a four rank assignment rule, and then press rank order sort on the line

The ac Code ( dish of chicken layout like him to forgive me ) (zu д⊂):

 

  . 1 #include <bits / STDC ++ H.>
   2  #define Rush () int T; the while (~ Scanf ( "% D", & T))
   . 3  the using  namespace STD;
   . 4  the using STD the bitset ::;
   . 5 typedef Long  Long LL;
   . 6  
  . 7 typedef struct 
  . 8  {
   . 9      String name;
 10      String card;
 . 11      int Rank1; // total rank 8 class type card 
12 is      int Rank2; // comparison rule with the same card type, assignment is not 0 
13 is      int rank3;
 14      intrank4;
 15  } man;
 16  
. 17  BOOL CMP (A man, man B) // Sort in order of priority rank ordered custom 
18 is  {
 . 19      IF (! = a.rank1 b.rank1)
 20 is          return a.rank1> B .rank1;
 21 is      the else 
22 is      {
 23 is          IF (= a.rank2! b.rank2)
 24              return a.rank2> b.rank2;
 25          the else 
26 is          {
 27              IF (! = a.rank3 b.rank3)
 28                  return a.rank3 > b.rank3;
 29              the else
 30             {
 31                 if(a.rank4!=b.rank4)
 32                     return a.rank4>b.rank4;
 33                 else
 34                     return a.name<b.name;
 35             }
 36         }
 37     }
 38 }
 39 
 40 man p[100005];
 41 
 42 
 43 int main()
 44 {
 45     rush()
 46     {
 47         for(int i=0;i<T;i++)
 48          {
 49              CIN >> P [I] .name >> P [I] .card;
 50              int FU [ 2 ] = { . 1 , . 1 }; // number of repetitions 
51 is              int F [ 2 ] = { 0 , 0 }; // corresponding duplicate card 
52 is              int FLG = 0 ;
 53 is              int SUM = 0 ; // . 5 and the card 
54 is              int CD [ . 5 ];
 55              for ( int J = 0 , Q =0 ; J <P [I] .card.length (); J ++, Q ++) // string input into a processing array 
56 is              {
 57 is                  IF (P [I] .card [J] == ' A ' )
 58                      CD [Q] = . 1 ;
 59                  the else  IF (P [I] .card [J] == ' J ' )
 60                      CD [Q] = . 11 ;
 61 is                  the else  IF (P [I] .card [J] == ' Q ' )
 62 is                      CD [Q] = 12 is ;
 63 is                  the else  IF (P [I] .card [J] =='K')
 64                     cd[q]=13;
 65                 else if(p[i].card[j]>='2'&&p[i].card[j]<='9')
 66                     cd[q]=p[i].card[j]-'0';
 67                 else if(p[i].card[j]=='1')
 68                 {
 69                     cd[q]=10;
 70                     j++;
 71                 }
72                  SUM = + CD [Q];
 73 is              }
 74              Sort (CD, CD + . 5 );
 75              // COUT << CD [0] << CD [. 1] << CD [2] << CD [. 3] << CD [. 4] << endl; 
76              for ( int J = 0 , Q = 0 ; J < . 4 ; J ++) // whether the calculated five cards and the corresponding duplicate card 
77              {
 78                  iF (CD [J] == CD [+ J . 1 ])
 79                  {
 80                      FU [Q] ++ ;
 81                      FLG = . 1 ;
 82                     F [Q] = CD [J];
 83                  }
 84                  the else 
85                  {
 86                      IF (FLG)
 87                      {
 88                          Q ++ ;
 89                          FLG = 0 ;
 90                      }
 91 is                  }
 92              }
 93              // by 8 kinds of big-type, respectively, to the back of the rank assignment 
94              IF (CD [ 0 ] == . 1 && CD [ . 1 ] == 10 && CD [ 2 ] ==11&&cd[3]==12&&cd[4]==13)
 95             {
 96                 p[i].rank1=8; p[i].rank2=0; p[i].rank3=0; p[i].rank4=0;
 97             }
 98             else if(cd[0]==cd[1]-1&&cd[1]==cd[2]-1&&cd[2]==cd[3]-1&&cd[3]==cd[4]-1)
 99             {
100                 p[i].rank1=7; p[i].rank2=cd[4]; p[i].rank3=0; p[i].rank4=0;
101             }
102             else if(fu[0]==4)
103             {
104                 p[i].rank1=6; p[i].rank2=f[0]; p[i].rank3=sum-4*f[0]; p[i].rank4=0;
105             }
106             else if(fu[0]==2&&fu[1]==3)
107             {
108                 p[i].rank1=5; p[i].rank2=f[1]; p[i].rank3=f[0]; p[i].rank4=0;
109             }
110             else if(fu[0]==3&&fu[1]==2)
111             {
112                 p[i].rank1=5; p[i].rank2=f[0]; p[i].rank3=f[1]; p[i].rank4=0;
113             }
114             else if(fu[0]==3&&fu[1]==1)
115             {
116                 p[i].rank1=4; p[i].rank2=f[0]; p[i].rank3=sum-3*f[0]; p[i].rank4=0;
117             }
118             else if(fu[0]==2&&fu[1]==2)
119             {
120                 p[i].rank1=3; p[i].rank2=f[1]; p[i].rank3=f[0]; p[i].rank4=sum-2*f[0]-2*f[1];
121             }
122             else if(fu[0]==2&&fu[1]==1)
123             {
124                 p[i].rank1=2; p[i].rank2=f[0]; p[i].rank3=sum-2*f[0]; p[i].rank4=0;
125             }
126             else
127             {
128                 p[i].rank1=1; p[i].rank2=sum; p[i].rank3=0; p[i].rank4=0;
129             }
130             //cout<<p[i].rank1<<" "<<p[i].rank2<<" "<<p[i].rank3<<" "<<p[i].rank4<<endl;
131         }
132         sort(p,p+T,cmp);
133         for(int i=0;i<T;i++)
134             cout<<p[i].name<<endl;
135     }
136     return 0;
137 }
View Code

 

Guess you like

Origin www.cnblogs.com/Find-sunrise-dream/p/11546141.html