HDU5228 ZCC loves straight flush

题目链接:

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=169624

题意:

判断同花顺,其中10 11 12 13 1也算。

思路:

他们说这是一题很简单的题,简单的列举一下所有同花顺的情况即可。

然而我并没有做出来。一,忽略了顺序打乱情况。二,忽略重复数据的情况。

于是产生新思路:对一个数a,前后找数如果在a+5的范围内并且没有访问过则mark值+1。对于1的情况需要特殊讨论。讨论得乱七八糟,不过好歹也算过了。

源码:

#include <cstdio>

#include <cstring>

#include <string>

#include <cmath>

#include <algorithm>

#include <iostream>

#include <cstdlib>

using namespace std;

char data1[10];

int data2[10];

struct D

{

   char data1;

   int data2;

}d[10];

char s[100];

char id[10] = {'A','B','C','D'};

int cmp[26][10];

void init()

{

   memset(cmp,0,sizeof(cmp));

   int now = 1;

   for(int i=0; i<9; i++){

       for(int j=0; j<5; j++){

           cmp[i][j] = now + j;

//            if(cmp[i][j]>13)

//                cmp[i][j] -= 13;

       }

       now++;

    }

   cmp[9][0] = 1;

   for(int j=1; j<5; j++){

       cmp[9][j] = now+j-1;

    }

}

bool cc(D a,D b)

{

 

   return a.data2<b.data2;

}

int main()

{

   init();

//   for(int i=0; i<10; i++){

//       for(int j=0; j<5; j++)

//            printf("%d ",cmp[i][j]);

//       printf("\n");

//   }

   int t;

   scanf("%d",&t);

   getchar();

   while(t--){

//       printf("t = %d\n",t);

       char c;

       int temp = 0;

       int step = 0;

//       cin.getline(s,100);

//       printf("%s\n",s);

       gets(s);

//       printf("%s\n",s);

       for(int i=0; i<strlen(s); i++){

 

           if(isdigit(s[i]))

                temp = temp*10 + s[i] - '0';

           else if(s[i]==' '){

                d[step++].data2 = temp;

                temp = 0;

           }

           else

                d[step].data1 = s[i];

       }

//       printf("temp = %d\n",temp);

       d[step++].data2 = temp;

//       printf("step =%d\n",step);

//       getchar();

//       while( c=getchar() ){

//            if(c == '\n'){

//                data2[step++] = temp;

//                break;

//            }

//            if(isdigit(c))

//                temp = temp*10+c-'0';

//            else if(c==' '){

//                data2[step++] = temp;

//                temp = 0;

//            }

//            else

//                data1[step] = c;

//       }

//       for(int i=0; i<5; i++)

//            printf("%c",data1[i]);

//       printf("\n");

//       for(int i=0; i<5; i++)

//            printf("%d ",data2[i]);

//       printf("\n");

//       sort(d,d+5,cc);

       int mmax = 0;

       int vis[10];

       for(int i=0; i<5; i++){

           memset(vis,0,sizeof(vis));

           vis[0] = 1;

           int mark = 1;

           for(int j=0; j<5; j++){

                if(i==j || d[i].data1 !=d[j].data1)

                    continue;

                int tt = d[j].data2 -d[i].data2;

                if(d[j].data2==1 &&tt<-5)

                    tt += 13;

                if(tt > 0 && tt<5&& vis[tt] == 0){

                    vis[tt] = 1;

                    mark++;

                }

           }

           mmax = max(mmax,mark);

       }

       printf("%d\n",5-mmax);

    }

   return 0;

}

你可能感兴趣的:(HDU5228 ZCC loves straight flush)