bzoj.1028. [JSOI2007] Mahjong (greedy)

Source: Internet
Author: User

Topic links

Enumerate pairs, enumerate each card, first out of its inscription, the rest of the straight. \ (O (n^3) \).
Not so----out of all the inscriptions, and finally the straight. (Daily ZZ)
The first three of the same, and then shun son, once and must use a chance to fill the empty space, that is, to replace the engraved pair. This seems to be \ (O (n^2) \).
Do not write \ (O (n^2) \) , the special sentence is probably very troublesome.

//828kb 396ms#include <cstdio>#include <cctype>#include <cstring>#define GC () GetChar ()Const intn=407;intN,m,tot,tmp[n],num[n],ans[n];inline intRead () {intnow=0;Register CharC=GC (); for(;! IsDigit (c); C=GC ()); for(; IsDigit (c); now=now*Ten+c-' 0 ', C=GC ());returnNow;}BOOLCheck () { for(intI=1; I<=n+2; ++i)//Finish processing the front before processing this one!         if((num[i]%=3) >0) num[i+1]-=num[i], Num[i+2]-=num[i], num[i]=0;//directly to lose the line, what        Else if(num[i]<0)return 0;return 1;}intMain () {N=read (), M=read (), tot=3*m+1; for(intI=1; i<=tot; ++i) ++tmp[read ()];intCnt=0; for(intI=1; i<=n; ++i) {++tmp[i]; for(intj=1; j<=n; ++J)if(tmp[j]>=2) {tmp[j]-=2, memcpy (Num,tmp,sizeofNUM), tmp[j]+=2;if(Check ()) {ans[++cnt]=i; Break;}    }--tmp[i]; }if(CNT) for(intI=1; i<=cnt; ++i) printf ("%d ", Ans[i]);ElsePuts"NO");return 0;}

bzoj.1028. [JSOI2007] Mahjong (greedy)

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.