题目链接:
PKU:http://poj.org/problem?id=3923
HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2487
Description
......................... ....AAAAAAAAAAAAA........ ....A...........A........ ....A...........A........ ....A...........A........ ....AAAAAAAAAAAAA........ ......................... Fig-1 ......................... ....AAAAAAAAAAAAA........ ....A...........A........ ....A.......BBBBBBBBBB... ....A.......B........B... ....AAAAAAAAB........B... ............BBBBBBBBBB... ......................... Fig-2 .......................... ....AAAAAAAAAAAAA......... ....A...........A......... ....A.......BBBBBBBBBB.... ....A.......B........BCCC. ....AAAAAAAAB........B..C. .......C....BBBBBBBBBB..C. .......CCCCCCCCCCCCCCCCCC. .......................... Fig-3
Input
Output
Sample Input
9 26 .......................... ....AAAAAAAAAAAAA......... ....A...........A......... ....A.......BBBBBBBBBB.... ....A.......B........BCCC. ....AAAAAAAAB........B..C. .......C....BBBBBBBBBB..C. .......CCCCCCCCCCCCCCCCCC. .......................... 7 25 ......................... ....DDDDDDDDDDDDD........ ....D...........D........ ....D...........D........ ....D...........D..AAA... ....DDDDDDDDDDDDD..A.A... ...................AAA... 0 0
Sample Output
B AD
Source
PS:注意:
7 25
...BBBBBBBBBBBBBBB.......
...BDDDDDDDDDDDDDB.......
...BDAAAAAAAAAAADB.......
...BDA.........ADB.......
...BDAAAAAAAAAAADB.......
...BDDDDDDDDDDDDDB.......
...BBBBBBBBBBBBBBB.......
6 6
AAABBB
A.AB.B
AAABBB
CCCDDD
C.CD.D
CCCDDD
代码如下:
#include<cstdio> #include<cstring> const int maxn = 217; char mp[maxn][maxn]; int vis[maxn]; int n,m; int ok(int a,int b) { int i, j; for(i = b; i <= m; i++) { if(mp[a][i]!=mp[a][b]) break; } i--; for(j = a+1; j <= n; j++) //行 { for(int k = b; k <= i; k++)//列 { if(k==b||k==i)//边缘不相同 { if(mp[j][k]!=mp[a][b]) return 0; } else if(mp[j][k]!='.')//底边 { for(int l = b; l <= i; l++) { if(mp[j][l]!=mp[a][b]) return 0; } return 1; } } } return 0; } int main() { int i,j; while(~scanf("%d%d",&n,&m)) { if(n==0 && m == 0) break; memset(vis,0,sizeof vis); for(int i = 0; i < n; i++) { scanf("%s",mp[i]); } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(mp[i][j]!='.'&&vis[mp[i][j]-'A']==0) { vis[mp[i][j]-'A']=1; if(ok(i,j)) vis[mp[i][j]-'A']=2; } } } int flag=1; for(int i = 0; i < 26; i++) { if(vis[i] == 2) { if(flag) printf("%c",i+'A'); else printf(" %c",i+'A'); } } puts(""); } }