Description
Question Bank link
Give you a pair of mahjong, the condition of the HU card is a pair will and a number of straight and engraved composition. Now give you \ (m\) cards, cards common \ (n\) species, ask you to listen to which card.
\ (1\leq n\leq 400,1\leq m\leq 1000\)
Solution
Consider enumerations to listen to that card, and then enumerate which pair to do.
For the rest of the cards, first from small to large to sweep once, if the current card number \ (>3\) , you can let its first Die \ (3\) , namely the composition of the inscription. This must be feasible, because let more than \ (3\) Zhang of the card composition shun son, then must be behind the card also if \ (3\) Zhang. But \ (3\) more than one can directly compose the inscription. So it must be feasible. Then the rest of the cards and the cards in the back make up a straight son. You only need to subtract the last two from the number of cards remaining in the sheet. It is not feasible to have negative numbers in the process of sweeping.
Code
//it is made by Awson on 2018.2.26#include <bits/stdc++.h>#define LL Long Long#define DOB complex<double>#define ABS (a) ((a) < 0? (-(a)): (a))#define MAX (A, B) ((a) > (b)? (a): (b))#define Min (A, B) ((a) < (b)? (a): (b))#define SWAP (A, B) ((a) ^= (b), (b) ^= (a), (a) ^= (b))#define WRITELN (x) (write (x), Putchar ('\n '))#define LOWBIT (x) ((x) & (-(x )))using namespaceStdConst intN = -;voidReadint&X) {CharChBOOLFlag =0; for(ch = getchar ();!isdigit (CH) && (flag |= (ch = ='-')) ||1); ch = getchar ()); for(x =0; IsDigit (CH); x = (x<<1) + (x<<3) +ch-48, ch = getchar ()); X *=1-2*flag;}voidPrintintx) {if(X >9) Print (x/Ten); Putchar (%10+48); }voidWriteintx) {if(X <0) Putchar ('-'); Print (Abs (x)); }intCnt[n+5], F[n+5], N, M, D, FLAG, Fla, BR, Ans[n+5], tot;voidWork () {scanf ("%d%d", &n, &m); for(inti =0; I <=3*m; i++) Read (d), ++cnt[d]; for(inti =1; I <= N; i++) {--cnt[i-1], ++cnt[i]; BR =0; for(intj =1; J <= N; J + +)if(Cnt[j] >=2) {if(BR) Break; FLA =0; for(intK =1; K <= N; k++) F[k] = cnt[k]; F[J]-=2; F[n+1] = F[n+2] =0; for(intK =1; K <= N; k++) {if(F[k] <0) {fla =1; Break; } F[k]%=3, F[k+1]-= F[k], f[k+2]-= f[k]; }if(F[n+1] <0|| F[n+2] <0) FLA =1;if(Fla = =0) flag = BR =1, Ans[++tot] = i; } }if(Flag = =0) puts ("NO");Else{ for(inti =1; i < tot; i++) write (Ans[i]), Putchar (' '); Writeln (Ans[tot]); }}intMain () {work ();return 0;}
[Jsoi 2007] Mahjong