POJ 2530Tetris Alphabet
来源:互联网 发布:山治两年后的实力知乎 编辑:程序博客网 时间:2024/05/17 07:54
Description
The game of Tetris is played with four-connected blocks falling down the well having N rows and 20 columns. Each figure is marked with a unique English letter from 'A' to 'Z'.
Your program must, given the state of the well, determine the order in which the blocks fell down.
Your program must, given the state of the well, determine the order in which the blocks fell down.
Input
The first line of input file contains integer N (1 <= N <= 50) -- number of rows. Following N lines contain 20 characters each, with characters that are either a letter from 'A' to 'Z' or the dot character (ASCII 46), representing an empty cell.
Output
Output file must contain a string of letters indicating the order in which figures fell down. If there is more than one order, lexicographically smallest one must be printed. Input data will guarantee that at least one nonempty order exists.
Sample Input
6...........XX.................MMMM................K.................KKK..............ZAAA.FFF............ZZZA..F.B......
Sample Output
BFZAKMX
拓扑排序
#include<cstdio>#include<iostream>#include<cstring>#include<map>#include<queue>#include<stack>#include<algorithm>#include<vector>#include<cmath>#include<string>#include<functional>using namespace std;const int maxn=10005;int T,n,f[30][30],c[30];char s[55][30];int main(){while (cin>>n){memset(f,0,sizeof(f));memset(c,-1,sizeof(c));for (int i=0;i<n;i++) {scanf("%s",s[i]);for (int j=0;s[i][j];j++) if (s[i][j]!='.'&&c[s[i][j]-'A']<0) c[s[i][j]-'A']=0;if (i) for (int j=0;s[i][j];j++)if (s[i][j]!='.'&&s[i-1][j]!='.')if (s[i][j]!=s[i-1][j]){ if (f[s[i][j]-'A'][s[i-1][j]-'A']==0) {f[s[i][j]-'A'][s[i-1][j]-'A']=1;c[s[i-1][j]-'A']++; }}}priority_queue<int,vector<int>,greater<int> > p;for (int i=0;i<26;i++)if (c[i]==0) p.push(i);while (!p.empty()){int k=p.top();printf("%c",k+'A');p.pop();for (int i=0;i<26;i++) if (f[k][i]) {c[i]--;if (c[i]==0) p.push(i);}}printf("\n");}return 0;}
0 0
- POJ 2530Tetris Alphabet
- POJ 2530 Tetris Alphabet 笔记
- poj 2530 Tetris Alphabet 拓扑排序
- POJ 1231 The Alphabet Game
- poj 1231 The Alphabet Game
- Alphabet
- POJ 1231 The Alphabet Game 笔记
- TETRIS
- Tetris
- POJ 3992 Tiles of Tetris, NOT!
- funny alphabet
- Greek alphabet
- Alphabet Cookies
- Google Alphabet
- greek alphabet
- Alphabet Cookies
- GSM 7bit alphabet
- Jambo Alphabet book - A
- AFNetworking 的导入(一)
- 浅谈java main()
- POJ 2350Above Average
- CEF Xilium.CefGlue 在当前窗口中打开所有链接(防止弹窗)
- Linux通配符
- POJ 2530Tetris Alphabet
- vim的使用
- wyh2000 and a string problem(模拟)
- Windows注册表详解
- swift2 类和结构体
- ios开发遇到的问题
- Java基础
- 1014. Waiting in Line (30)
- 51nod 1091 线段的重叠