Test instructions
To a Tetris game where each input block is marked with a A-Z symbol, which asks for the smallest input order of the dictionary order of the input block.
Analysis:
The topological order with the smallest dictionary order is obtained.
Code:
POJ 2530//sep9#include <iostream>using namespace Std;char map[54][32];int g[32][32];int d[32];int vis[32];int Main () {int n;scanf ("%d", &n), memset (G,0,sizeof (g)); Memset (d,0,sizeof (d)); Memset (vis,0,sizeof (VIS)); for (int i= 0;i<n;++i) scanf ("%s", Map[i]), for (Int. i=0;i<n;++i) for (int j=0;j<20;++j) if (map[i][j]!= '. ') {int u=map[i][j]-' A '; vis[u]=1;for (int k=0;k<i;++k) if (map[k][j]!= '. ') &&MAP[K][J]!=MAP[I][J]) {int v=map[k][j]-' A '; if (g[u][v]==0) {g[u][v]=1;++d[v];}}} int I,t;while (1) {t=-1;for (i=0;i<26;++i) if (vis[i]==1&&d[i]==0&&t==-1) {t=i;vis[i]=0;} if (t==-1) break;printf ("%c", ' A ' +t); for (i=0;i<26;++i) if (G[t][i]==1&&vis[i])--d[i];} return 0;}
POJ 2530 Tetris Alphabet topological ordering