Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:是非常恶心!!!In Reply To:是非常恶心!!! Posted by:dut200901102 at 2011-08-09 21:08:18 > Source Code > > Problem: 3966 User: dut200901102 > Memory: 168K Time: 47MS > Language: C++ Result: Accepted > > Source Code > #include <cstdio> > #include <cstring> > #include <algorithm> > #include <iostream> > > using namespace std; > > struct node{int t;char c;}p[5]; > > int get_num(char st) > { > if(st=='T')return 10; > if(st=='J')return 11; > if(st=='Q')return 12; > if(st=='K')return 13; > if(st=='A')return 14; > return st-'0'; > } > bool operator < (const node &x,const node &y) > { > return x.t<y.t; > } > void init() > { > char st[3]; > for(int i=0;i<5;++i) > { > scanf("%s",st); > p[i].c=st[1],p[i].t=get_num(st[0]); > } > sort(p,p+5); > // for(int i=0;i<5;++i)cout<<p[i].t<<" ";cout<<endl; > // for(int i=0;i<5;++i)cout<<p[i].c<<" ";cout<<endl; > } > bool Straight(int &top) > { > if(p[0].t==2&&p[1].t==3&&p[2].t==4&&p[3].t==5&&p[4].t==14){top=5;return true;} > for(int i=1;i<5;++i) > if(p[i].t!=p[i-1].t+1)return false; > top=p[4].t; > return true; > } > bool Flush() > { > for(int i=1;i<5;++i) > if(p[i].c!=p[i-1].c)return false; > return true; > } > bool Straight_Flush(int &top) > { > return (Straight(top)&&Flush()); > } > bool Four_of_a_Kind(int &top,int &top1) > { > if(p[0].t==p[3].t){top=p[0].t,top1=p[4].t;return true;} > if(p[1].t==p[4].t){top=p[1].t,top1=p[0].t;return true;} > return false; > } > bool Full_House(int &top,int &top1) > { > if(p[0].t==p[2].t&&p[3].t==p[4].t){top=p[0].t,top1=p[4].t;return true;} > if(p[2].t==p[4].t&&p[0].t==p[1].t){top=p[2].t,top1=p[0].t;return true;} > return false; > } > bool Three_of_a_Kind(int &top,int &top1,int &top2) > { > if(p[0].t==p[2].t){top=p[0].t,top1=p[4].t,top2=p[3].t;return true;} > if(p[1].t==p[3].t){top=p[1].t,top1=p[4].t,top2=p[0].t;return true;} > if(p[2].t==p[4].t){top=p[2].t,top1=p[1].t,top2=p[0].t;return true;} > return false; > } > bool Two_Pairs(int &top,int &top1,int &top2) > { > if(p[0].t==p[1].t&&p[2].t==p[3].t){top=p[2].t,top1=p[0].t,top2=p[4].t;return true;} > if(p[0].t==p[1].t&&p[3].t==p[4].t){top=p[3].t,top1=p[0].t,top2=p[2].t;return true;} > if(p[1].t==p[2].t&&p[3].t==p[4].t){top=p[3].t,top1=p[1].t,top2=p[0].t;return true;} > return false; > } > bool One_Pair(int &top,int &top1,int &top2,int &top3) > { > if(p[0].t==p[1].t){top=p[0].t,top1=p[4].t,top2=p[3].t,top3=p[2].t;return true;} > if(p[1].t==p[2].t){top=p[1].t,top1=p[4].t,top2=p[3].t,top3=p[0].t;return true;} > if(p[2].t==p[3].t){top=p[2].t,top1=p[4].t,top2=p[1].t,top3=p[0].t;return true;} > if(p[3].t==p[4].t){top=p[3].t,top1=p[2].t,top2=p[1].t,top3=p[0].t;return true;} > return false; > } > int get_rank_common() > { > int cnt=1; > for(int i1=2;i1<=14;++i1) > for(int i2=2;i2<i1;++i2) > for(int i3=2;i3<i2;++i3) > for(int i4=2;i4<i3;++i4) > for(int i5=2;i5<i4;++i5) > { > if(i5+1==i4&&i4+1==i3&&i3+1==i2&&i2+1==i1)continue; > if(i1==14&&i2==5&&i3==4&&i4==3&&i5==2)continue; > if(i1==p[4].t&&i2==p[3].t&&i3==p[2].t&&i4==p[1].t&&i5==p[0].t)return cnt; > cnt++; > } > } > int get_rank_3K(int top,int top1,int top2) > { > int cnt=1; > for(int u=2;u<=14;++u) > for(int i=2;i<=14;++i) > if(i!=u) > for(int j=2;j<i;++j) > if(j!=u) > { > if(j==top2&&i==top1&&u==top)return cnt; > cnt++; > } > } > int get_rank_2P(int top,int top1,int top2) > { > int cnt=1; > for(int i=2;i<=14;++i) > for(int j=2;j<i;++j) > for(int k=2;k<=14;++k) > { > if(k==i||k==j)continue; > if(i==top&&j==top1&&k==top2)return cnt; > cnt++; > } > } > int get_rank_1P(int top,int top1,int top2,int top3) > { > int cnt=1; > for(int u=2;u<=14;++u) > for(int i=2;i<=14;++i) > if(i!=u) > for(int j=2;j<i;++j) > if(j!=u) > for(int k=2;k<j;++k) > if(k!=u) > { > if(top==u&&top3==k&&top2==j&&top1==i)return cnt; > cnt++; > } > } > int solve() > { > int top,top1,top2,top3; > if(Straight_Flush(top)) > return 7452+top-4; > if(Four_of_a_Kind(top,top1)) > return 7296+(top-2)*12+top1-1-(top1>top); > if(Full_House(top,top1)) > return 7140+(top-2)*12+top1-1-(top1>top); > if(Flush()) > return 5863+get_rank_common(); > if(Straight(top)) > return 5853+top-4; > if(Three_of_a_Kind(top,top1,top2)) > return 4995+get_rank_3K(top,top1,top2); > if(Two_Pairs(top,top1,top2)) > return 4137+get_rank_2P(top,top1,top2); > if(One_Pair(top,top1,top2,top3)) > return 1277+get_rank_1P(top,top1,top2,top3); > return get_rank_common(); > } > int main() > { > // freopen("in.txt","r",stdin); > init(); > printf("%d\n",solve()); > return 0; > } > Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator