HDU 4431 Mahjong question

Source: Internet
Author: User

This is my last question in my career. Acm has left me too much... No.

The basic thing is to use enumeration + greedy.

But there are several minor issues:

1. Seven small pairs are seven different pairs.

2. east, west, north, south, and so on cannot be shunzi.

Considering these two points, there is basically no trick.

#include<iostream>using namespace std;int cnt[35];int maso[14]={0,8,9,17,18,26,27,28,29,30,31,32,33};int f( char c ){ if( c>='1' && c<='9' ) return c-'1'; if( c=='m' ) return 0; if( c=='s' ) return 9; if( c=='p' ) return 18; return 27;}char mspc( int x ){ if( x==0 ) return 'm'; if( x==1 ) return 's'; if( x==2 ) return 'p'; return 'c'; }bool judge4x3(){  int i,j,ret=0;   int tem[34];  for( i=0;i<34;i++ ) tem[i]=cnt[i];  for( i=0;i<=18;i+=9 )  for( j=0;j<9;j++ )  {    if( tem[i+j]>=3 )      tem[i+j]-=3,ret++;    while( j+2<9 && tem[i+j]&& tem[i+j+1]&& tem[i+j+2] )    tem[i+j]--,tem[i+j+1]--,tem[i+j+2]--,ret++; } i=27;  for( j=0;j<7;j++ )  {    if( tem[i+j]>=3 )      tem[i+j]-=3,ret++; } return ret==4?true:false;}bool judge1(){  for( int i=0;i<34;i++ )  {    if( cnt[i]>=2 )    {     cnt[i]-=2;     if( judge4x3() )     {     cnt[i]+=2;       return true;    }     cnt[i]+=2;  } } return false;}bool judge2()//judge Chii Toitsu{  for( int i=0;i<34;i++ )    if( cnt[i]!=2 && cnt[i]!=0 )  return false;  return true;}bool judge3(){  for( int i=0;i<7;i++ )    if( cnt[i+27]==0 )      return false;  for( int i=0;i<=18;i+=9 )  {    if( cnt[i]==0 || cnt[i+8]==0 )      return false;    for( int j=1;j<8;j++ )       if( cnt[i+j] )          return false; }  return true;}bool judge(){  if( judge1() ) return true;  if( judge2() ) return true;  if( judge3() ) return true;  return false;}int main(){ //freopen( "A.in","r",stdin ); //freopen( "A.out","w",stdout ); int T; scanf( "%d",&T ); while( T-- ) {    char com[11];    int rec[34],tot=0;    memset( cnt,0,sizeof(cnt) );    for( int i=0;i<13;i++ )    {   scanf("%s",com);   cnt[f(com[0])+f(com[1])]++;   }   for( int i=0;i<34;i++ )   {   cnt[i]++;   if( cnt[i]<=4 && judge() )   rec[tot++]=i;   cnt[i]--;      }      if( tot==0 )         printf( "Nooten" );      else      {      printf( "%d",tot );      for( int i=0;i<tot;i++ )      printf( " %d%c",rec[i]%9+1,mspc(rec[i]/9) );      }   printf( "\n" );  }  return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.