1028: [JSOI2007] Mahjong
Time Limit:1 Sec
Memory limit:256 MB
Topic Connection http://www.lydsy.com/JudgeOnline/problem.php?id=1028
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 8
Sample Output
6 7 9HINT
Test instructions
Exercises
The range of n is only 400, so just dumb and violent.
Enumerate each card, enumerate each pair ...
The first thing that becomes the inscription is the inscription, and then the straight.
Code:
//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<bitset>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 500#defineMoD 1001#defineEPS 1e-9#definePi 3.1415926intNum;//const int INF=0X7FFFFFFF;Constll inf=999999999; inline ll read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//*************************************************************************************intA[MAXN];intB[maxn];vector<int>ans;intn,m;intJud () { for(intI=1; i<=n;i++) { for(intj=1; j<=n;j++) B[j]=A[j]; intAns =0; if(b[i]>=2) {B[i]-=2; Ans+=2; for(intj=1; j<=n;j++) {Ans+=3* (b[j]/3); B[J]%=3; if(b[j]==0)Continue; if(b[j+1]==0|| b[j+2]==0)Continue; B[J]--, b[j+1]--, b[j+2]--; J--; ans+=3; } } if(ans==m*3+2) return 1; } return 0;}intMain () {n=read (); m=read (); for(intI=1; i<=3*m+1; i++) { intx=read (); A[X]++; } for(intI=1; i<=n;i++) {A[i]++; if(Jud ()) ans.push_back (i); A[i]--; } if(ans.size () = =0) {printf ("no\n");} Else{sort (Ans.begin (), Ans.end ()); for(intI=0; I<ans.size (); i++) { if(i!=0) printf ("%d", Ans[i]); Elseprintf"%d", Ans[i]); } printf ("\ n"); }}
Bzoj 1028: [JSOI2007] Mahjong violence