1028: [JSOI2007] Mahjong time limit:1 Sec Memory limit:162 MB
submit:1270 solved:576
[Submit] [Status] [Discuss] Description
Mahjong is one of the traditional entertainment tools in China. Mahjong card can be divided into cards (a total of East, south, west, north, middle, fat, white seven kinds) and the number of cards (divided into a sliver, pancake, thousand three kinds of suits, each suit has one to nine nine kinds of cards), each of the four cards. In Mahjong, usually a group of cards (i.e. the finished card) is made up of 14 cards. 14 cards in two pairs (that is, the same two cards), the remaining 12 are composed of three groups of four groups, each group must be a straight (that is, the same suit and ordinal number of the number of cards, such as the three, four or five) or the inscription (that is, the exact 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 plus card can be called a waiting card. 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 number 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 cards, of which two are made up of pairs, the remaining 3m are composed of three groups of M group, each group shall be straight or engraved. Now give a set of 3m + 1 cards, ask to determine whether the group card is a draw (that is, 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 integers separated by spaces, each within a 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 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 9HINT Source
Problem: Sand tea ... Nest Meng Enumeration listen to which card, then enumerate will ... (because this problem can not be listened to??!!!!!!!!!! How come I didn't know it at first? Why???!!! What are your conscience? )
Do you know how to judge the legality of spicy? Satay!!! Nest Meng sweep again, the touch on the touch, the eat will eat not just finished ... Qaq ... (I started thinking about a half-day construction ... )
Code:
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn=10000+Ten, maxm= -+Ten; One intcnt,m,a[maxn],num[maxm],ans[maxn],total; A BOOLJudge () { - Static ints[maxn],lim=cnt+2; - for(intI=1; i<=lim;i++) s[i]=Num[i]; the for(intI=1; i<=lim;i++){ - if(s[i]<0)return false; -s[i]%=3; s[i+1]-=s[i];s[i+2]-=S[i]; -}return true; + } -InlineintRead () { + intx=0, sig=1;CharCh=GetChar (); A while(!isdigit (CH)) {if(ch=='-') sig=-1; ch=GetChar ();} at while(IsDigit (CH)) x=Ten*x+ch-'0', ch=GetChar (); - returnx*=Sig; - } -InlinevoidWriteintx) { - if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; - intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; in for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } to voidinit () { +cin>>cnt>>m;Static intAll=3*m+2; - for(intI=1; i<all;i++) a[i]=read (); the for(intI=1; i<=cnt;i++){ *A[all]=i;memset (NUM,0,sizeof(num)); $ for(intj=1; j<=all;j++) + +Num[a[j]];Panax Notoginseng for(intj=1; j<=cnt;j++)if(num[j]>=2){ -num[j]-=2;if(Judge ()) {ans[++total]=i; Break;} num[j]+=2; the } + } A if(!total) {Puts ("NO");return;} theWrite (ans[1]); + for(intI=2; i<=total;i++) Pau,write (Ans[i]); - return; $ } $ voidWork () { - return; - } the voidprint () { - return;Wuyi } the intMain () {init (); work ();p rint ();return 0;}
Bzoj 1028 [JSOI2007] Mahjong