HDU 5228 ZCC loves straight flush 暴力

题目链接:

hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5228

bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=582&pid=1001

题解:

首先可以先考虑花色,把输入按照花色分组,对于每种花色同花顺的情况只有十种:(1,2,3,4,5)~(10,11,12,13,1),然后对每种花色的每种同花顺都对照一下,看看当前的牌有几张不在里面,这几张牌就是我们要替换的了,全部的情况都跑一遍取最小值。

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<vector>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 const int maxn=22;
 9 const int INF=0x3f3f3f3f;
10 
11 //mat[i]表示第i种同花顺的状态 
12 int mat[maxn][maxn];
13 
14 //输入按花色分组 
15 vector<int> arr[maxn];
16 
17 void get_mat(){
18     memset(mat,0,sizeof(mat)); 
19     for(int i=0;i<10;i++){
20         for(int j=0;j<5;j++){
21             mat[i][(i+j)%13+1]=true;
22         }
23     }
24 }
25 
26 //暴力枚举 
27 void solve(int cur,int *ma,int &ans){
28     int cnt=0;
29     for(int i=0;i<arr[cur].size();i++){
30         int x=arr[cur][i];
31         if(ma[x]) cnt++;
32     }
33     ans=min(ans,5-cnt);
34 }
35 
36 void init(){
37     for(int i=0;i<maxn;i++) arr[i].clear();
38 } 
39 
40 int main(){
41     get_mat();
42     int tc;
43     scanf("%d",&tc);
44     while(tc--){
45         init();
46         char ch[11];
47         for(int i=0;i<5;i++){
48             scanf("%s",ch);
49             if(ch[2]!='\0'){
50                 int tmp=(ch[1]-'0')*10+ch[2]-'0';
51                 arr[ch[0]-'A'].push_back(tmp);
52             }
53             else arr[ch[0]-'A'].push_back(ch[1]-'0');
54         }
55         int ans=INF;
56         for(int i=0;i<4;i++){
57             for(int j=0;j<10;j++){
58                 solve(i,mat[j],ans);
59             }
60         }
61         printf("%d\n",ans);
62     }
63     return 0; 
64 }

 

转载于:https://www.cnblogs.com/fenice/p/5388009.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值