Vijos 1030 Overlapping Squares

Source: Internet
Author: User

is a block diagram of 5 dots placed in the 9x8:

If they are stacked up in order. Some of the boxes cover the other box, covering some parts.
This is the 5-box-stacked graph:

So what is the order of the boxes from bottom to top?
The answer is: EDABC.
Your task is to stack the graphics after a given box is stacked and find out their stacking order from bottom to top.
Here are some rules:
(1). The edge width of the box is one character and the edge length is not less than 3 characters;
(2). Each of the 4 edges of the box is visible, and a corner represents two edges;
(3). The box is capitalized, and no two squares are represented by the same characters.

Format input Format

The first two lines have a number for each line, indicating the length and width respectively.

Next is a picture of the box stacked up. Where there is no box, use '. ' Said.

Output format

Output all possible scenarios.

Sort by dictionary order.

Thinking of solving problems

Probably is to find the border and then judge the box above it, build the map, and make the DFS with the topological sort

1 varN,m,i,j,max:longint;2 Ch:char;3F:Array[0.. +,0.. +] ofLongint;4dt:array[1.. -,1.. -] ofLongint;5U,d,l,r,c,w:Array[1.. -] ofLongint;6Pd:Array[1.. -] ofBoolean;7 procedureDFS (i,k:longint);//Dfs with topological sort8 varJ:longint;9 beginTen  Onew[k]:=i; A     ifK=max Then -     begin -          forj:=1  toMax DoWrite (char (w[j]+ -)); the Writeln; - exit; -     End; -      forj:=1  toMax Do +  - Dec (c[j],dt[j,i]); +  A      forj:=1  toMax Do at         if(c[j]=0) and( notPD[J]) Then -         begin -pd[j]:=true; -  -DFS (j,k+1); -pd[j]:=false; in         End; -          forj:=1  toMax Do to Inc (C[j],dt[j,i]); +  - End; the  * procedureInit; $ varI,j:longint;Panax Notoginseng begin -READLN (n,m);//Readings the      fori:=1  toN Do +     begin A          forj:=1  toM Do the         begin + read (CH); -             ifCh='.'  Thenf[i,j]:=0; $             ifChinch['A'..'Z'] ThenF[i,j]:=ord (CH)- -; $             ifF[i,j]>max Thenmax:=F[i,j]; -         End; - Readln; the     End; -Filldword (U,length (U), +);WuyiFilldword (L,length (L), +); the      fori:=1  toN Do//looking for the left and right borders -          forj:=1  toM Do Wu         ifF[i,j]<>0  Then -         begin About             ifU[f[i,j]]>i Thenu[f[i,j]]:=i; $             ifL[f[i,j]]>j Thenl[f[i,j]]:=J; -             ifR[f[i,j]]<j Thenr[f[i,j]]:=J; -             ifD[f[i,j]]<i Thend[f[i,j]]:=i; -         End; A  +     {Determine if there are other numbers on the bounds of the box, if any, assign a value of f[i,j] to 1, indicating I is above J, build} the      fori:=1  toMax Do -     begin $          forJ:=u[i] toD[i] Do the         begin the             if(F[j,l[i]]<>i) Thendt[f[j,l[i]],i]:=1; the             if(F[j,r[i]]<>i) Thendt[f[j,r[i]],i]:=1; the         End; -          forJ:=l[i] toR[i] Do in         begin the             if(F[u[i],j]<>i) Thendt[f[u[i],j],i]:=1; the             if(F[d[i],j]<>i) Thendt[f[d[i],j],i]:=1; About         End; the     End; the End; the begin + Init; -      fori:=1  toMax Do//looking for points out of each other the          forj:=1  toMax DoBayi Inc (C[i],dt[i,j]); the      fori:=1  toMax Do ifc[i]=0  Then//The out degree is 0, indicating the bottom the     begin -pd[i]:=true; -DFS (I,1); thepd[i]:=false; the     End; the End.

Vijos 1030 Overlapping Squares

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.