Frame Stacking
| Time Limit: 1000MS |
|
Memory Limit: 10000K |
| Total Submissions: 4454 |
|
Accepted: 1509 |
Description
Consider the following 5 picture frames placed in an 9 x 8 array.
........ ........ ........ ........ . Ccc.... Eeeeee. ........ ........ .. BBBB. . C.C .... E.... E. dddddd. ........ .. B.. B... C.C .... E.... E.. D ..... D............ B.. B... Ccc.... E.... E.. D ..... D...... Aaaa.. B.. B.......... E.... E.. D ..... D...... A.. A.. BBBB. ........ E.... E. dddddd. .... A.. A................ E.... E.............. Aaaa................ Eeeeee. ........ ........ ........ ........ 1 2 3) 4 5
Now place them on top of one another starting with 1 at the bottom and ending up with 5 on top. If any part of a frame covers another it hides that part of the frame below.
Viewing the stack of 5 frames we see the following.
. Ccc.... ECBCBB. Dcbcdb. DCCC. B.. D.b.abaad. BBBB. Addddad. Ae... Aaaaeeeeee.
In what order is the frames stacked from bottom to top? The answer is EDABC.
Your problem is to determine the order in which the frames be stacked from bottom to top given a picture of the stacked F Rames. Here is the rules:
1. The width of the frame is always exactly 1 character and the sides are never shorter than 3 characters.
2. It is possible to see at least one part of each of the four sides of a frame. A corner shows and sides.
3. The frames is lettered with capital letters, and No, and no, frames would be assigned the same letter.
Input
Each input block contains the height, h (h<=30) on the first line and the width W (w<=30) on the second. A picture of the stacked frames are then given as h strings with w characters each.
Your input may contain multiple blocks of the format described above, without a blank lines in between. All blocks in the input must is processed sequentially.
Output
Write the solution to the standard output. Give the letters of the frames in the order they were stacked from bottom to top. If There is multiple possibilities for the ordering, list all such possibilities in alphabetical order, each one on a Sepa Rate line. There always is at the least one legal ordering for each input block. List the output for all blocks in the input sequentially, without a blank lines (not even between blocks).
Sample Input
98.CCC .... ECBCBB. Dcbcdb. DCCC. B.. D.b.abaad. BBBB. Addddad. Ae... Aaaaeeeeee.
Sample Output
Edabc
Source
Southern African 2001 Test instructions:a two-dimensional diagram has several frames (four-edged, hollow rectangles with a border surrounded by the same character), and each border character is different. BorderOverlapping , the order of overlap is obtained.
1. Multiple sets of outputs, with indeterminate conditions all output, sorted in dictionary order. 2. The frame in the diagram gives 4 edges (one vertex includes 2 edges), which can infer the length and position of the frame.
Ideas:
1. The determination of the rectangle, by the condition of the known, each rectangle can be represented by four sides, the minimum upx and maximum dowx, ordinate minimum ly and the maximum Ry, to determine the only. Then traverse the four edges to determine the border a. To find out which border B is above the border, add a forward edge from A to B.
2. Then there is the DFS-type topology ordering.
#include <stdio.h> #include <string.h> #include <vector>using namespace std;const int N = 40;struct frame{int ux,dx,ly,ry; Frame four-side};bool Exist[n]; int in[n],n,path[n]; vector<int>mapt[n];void tope (int u,int k) {path[k]=u; if (k==n) {for (int i=1;i<=k;i++) printf ("%c", path[i]+ ' A '); printf ("\ n"); return; } in[u]=-1; int len=mapt[u].size (); for (int i=0;i<len;i++)//Off-edge in[mapt[u][i]]--; for (int i=0;i<26;i++) if (exist[i]&&in[i]==0)//condition: There is a class I border, and the in degree is 0 tope (i,k+1); for (int i=0;i<len;i++)//restore Edge in[mapt[u][i]]++; in[u]=0;} Char str[n][n];void Buildmap (frame b[]) {bool have[n][n]={0}; int ch,l,r,x,y; for (int i=0;i<26;i++) if (Exist[i]) {x=b[i].ux; l=b[i].ly; R=b[i].ry; while (l<=r) {if (str[x][l]!= '. ') &&str[x][l]-' A '!=i) {ch=str[x][l]-' a '; have[i][ch]=1;} l++; } X=B[I].DX l=b[i].ly; R=b[i].ry; while (l<=r) {if (str[x][l]!= '. ') &&str[x][l]-' A '!=i) {ch=str[x][l]-' a '; have[i][ch]=1;} l++; } y=b[i].ly; L=b[i].ux; R=B[I].DX; while (l<=r) {if (str[l][y]!= '. ') &&str[l][y]-' A '!=i) {ch=str[l][y]-' a '; have[i][ch]=1;} l++; } Y=b[i].ry; L=b[i].ux; R=B[I].DX; while (l<=r) {if (str[l][y]!= '. ') &&str[l][y]-' A '!=i) {ch=str[l][y]-' a '; have[i][ch]=1;} l++; } for (int j=0;j<26;j++) if (Have[i][j]) {in[j]++; Mapt[i].push_back (j); The J-Class border is above the class I border}}}int main () {frame board[n]; int h,w; while (scanf ("%d", &h) >0) {scanf ("%d", &w); n=0; for (int i=0;i<=30;i++) {mapt[i].clear (); in[i]=0; Exist[i]=false; Board[i].ux=board[i]. ly=n; Board[i].dx=board[i].ry=-1; } for (int i=0;i
POJ1128 Frame Stacking (topological sort) Classic