The learning of BZOJ1298 dice

Source: Internet
Author: User

Exercises

Consider the AI as the father of I, so that they connect to the edge, then the topic gives the relationship formed a base ring tree forest.

For the outer ring, the edge of the ring (that is, the "tree" part), so that each face of the dice than their father.

Observation of 1, 4 example can find a construction mode: for a size of N-ring, starting from the first point, against the father side into the 1~n, and then from the first point in the ring of the son began, against the father side to put n+1~2*n, know to fill n*m number.

However, this constructor failed in sample 3. In fact, it can be proved that this method will be invalidated only if the ring size is 3 and the dice face number is 4 in the case of a decent example 3. In this case, the Special award.

Note that the ring size is 2 or m<=2, it must not be constructed.

Code:

ConstBB:Array[1.. A] ofLongint= (1,2,4,3,7,5,Ten,8,6, One,9, A);varI,j,k,l,n,m,cnt:longint; Fa,a,b,c:Array[0..1001] ofLongint; D:Array[0..1001,0..1001] ofLongint;procedureSS2 (x:longint);varI:longint;begin  ifa[x]<2  Then  begin     fori:=1  toM Do    beginInc (CNT); d[x,i]:=cnt;End; A[X]:=2; End; I:=C[x];  whileI>0  Do  begin    ifa[i]<2  ThenSS2 (i); I:=B[i]; End;End;procedureSS (X:longint);varI,j,k,l,xx:longint;beginA[x]:=1; x:=Fa[x];  whilea[x]=0  Do  beginA[x]:=1; x:=Fa[x]; End; K:=1; XX:=FA[X]; a[x]:=2;  whileX<>xx Do beginInc (k); a[xx]:=2; XX:=FA[XX];End; ifk<=2  Then beginWriteln (0); HaltEnd; if(k=3) and(m=4) Then  begin     fori:=1  to  A  Do    beginD[x,1+ ((I-1)Div 3)]:=Bb[i]; X:=Fa[x]; End; End Else  begin     fori:=1  toM Do    beginL:=cnt+K;  forj:=1  toK Do      beginD[x,i]:=l; Dec (l); ifJ<>k Thenx:=Fa[x]; End; CNT:=cnt+K; End; End;  fori:=1  toK Do  beginSS2 (x); x:=Fa[x]; End;End;beginreadln (n,m);  fori:=1  toN Do  beginread (fa[i]); B[i]:=c[fa[i]]; c[fa[i]]:=i; End;  fori:=1  toN Do  ifa[i]=0  ThenSS (i);  fori:=1  toN Do  begin     forj:=1  toM DoWrite (D[i,j],' ');  Writeln; End;End.

The learning of BZOJ1298 dice

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.