zoukankan      html  css  js  c++  java
  • 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]!=''){
    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
    ",ans);
    62     }
    63     return 0; 
    64 }
  • 相关阅读:
    c++ 反汇编 堆变量
    glibc源码逆向——fread函数
    glibc源码逆向——fopen
    buu查漏补缺刷题(3)
    gyctf_2020_borrowstack
    实现用句柄表反调试
    pwnable_orw 学习shellcraft新花样
    buu查漏补缺刷题(2)
    gdb调试源码
    buu查漏补缺刷题(1)
  • 原文地址:https://www.cnblogs.com/fenice/p/5388009.html
Copyright © 2011-2022 走看看