[JSOI2007] Mahjong

Source: Internet
Author: User

Description

Mahjong is one of the traditional entertainment tools in China. Mahjong card can be divided into a number of cards (east, south, west, north, middle, fat, white seven kinds) and ordinal numbers
Cards (divided into three kinds of stripes, pancake, thousand, each suit has one to nine of nine kinds of cards), each of the four cards. In Mahjong, it is often the case that a
The group and the cards (i.e. the completed cards) consist of 14 cards. Two of the 14 cards are paired (the exact same two cards), and the remaining 12
Consisting of three groups of four, each group shall be a straight (that is, the same suit and the ordinal number of the number of cards, such as the three, four or five of the sliver) or the inscription (i.e.
Exactly the same three cards). A set of cards refers to a group of 13 cards, and plus a certain card can be composed and cards. That one plus card can
Called Waiting cards. Here, we consider a special kind of mahjong. In this special kind of mahjong, there is no word card, there is only one color. However, the ordinal
is not limited to a range of one to nine, but within the range of 1 to N. At the same time, there is no limit of four cards per card. A set of cards made up of 3m + 2 sheets
Card composition, of which two are composed of pairs, the remaining 3m sheets comprise three groups of M group, each group shall be straight or engraved. Now give a set of 3m + 1 cards, to
To determine whether the group card is a draw (that is, another one can and cards). If so, output all possible waiting cards.

Input

contains two lines. The first line consists of two integers separated by spaces N, M (9<=n<=400, 4<=m<=1000). The second line contains 3m + 1 spaces separated by a space
integers, each of which is within the range of 1 to N. These numbers represent the number of cards that are required to judge the draw.

Output

The output is one line. If the deck is a draw, all the possible waiting cards are output, separated by a space. All the ordinals
Must be output in order from small to large. If the deck is not a draw, the output is "NO".

Sample Input9 4
1 1 2 2 3 3 5 5 5 7 8 8 8Sample Output6 7 9enumerate the waiting cards firstTo enumerate the pairs againand decide if you play.

If we set the $e$ array to be the state of the current card, then the key code is:

e[j]%=3;e[j+1]-=e[j];e[j+2]-=e[j];

Then when $e[j]<0$ the card is not the card.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6 using namespacestd;7 intt[501],f[501],n,m,pd,flag;8 intMain ()9{intx,i,j,k;TenCin>>n>>m; One    for(i=1; i<=3*m+1; i++) A     { -scanf"%d",&x); -t[x]++; the     } -Pd=0; -    for(i=1; i<=n;i++) -     { +t[i]++; -flag=0; +        for(j=1; j<=n;j++) A     { at       if(t[j]>=2) -         { -            for(k=1; k<=n+2; k++) -f[k]=T[k]; -f[j]-=2; -            for(k=1; k<=n+2; k++) in         { -           if(f[k]<0) to             { +                Break; -             } thef[k]%=3; *f[k+1]-=F[k]; $f[k+2]-=F[k];Panax Notoginseng         } -           if(k==n+3) the         { +flag=1; A           if(pd==0) printf ("%d", i); the           Elseprintf"%d", i); +            Break; -         } $         } $     } -       if(flag) pd=1; -t[i]--; the     } -   if(!PD) printf ("no\n");Wuyi}

[JSOI2007] Mahjong

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.