简单DP
#include<iostream> #include<cstdio> #include<cstring> using namespace std; char map[2][1410]; int S[4][2][1410],s[4][2][1410],smax,Smax; int max(int a,int b) { return a > b ? a : b; } int work(int n,int e) { int i; for(i=1;i<=n;i++) { if(map[e][i]=='S') { if(map[1-e][i]=='S') S[0][e][i]=S[0][1-e][i]+1; else S[0][e][i]=1; if(map[e][i-1]=='S') S[1][e][i]=S[1][e][i-1]+1; else S[1][e][i]=1; if(map[1-e][i-1]=='S') S[2][e][i]=S[2][1-e][i-1]+1; else S[2][e][i]=1; if(map[1-e][i+1]=='S') S[3][e][i]=S[3][1-e][i+1]+1; else S[3][e][i]=1; } if(map[e][i]=='s') { if(map[1-e][i]=='s') s[0][e][i]=s[0][1-e][i]+1; else s[0][e][i]=1; if(map[e][i-1]=='s') s[1][e][i]=s[1][e][i-1]+1; else s[1][e][i]=1; if(map[1-e][i-1]=='s') s[2][e][i]=s[2][1-e][i-1]+1; else s[2][e][i]=1; if(map[1-e][i+1]=='s') s[3][e][i]=s[3][1-e][i+1]+1; else s[3][e][i]=1; } Smax=max(Smax,max(max(S[0][e][i],S[1][e][i]),max(S[2][e][i],S[3][e][i]))); smax=max(smax,max(max(s[0][e][i],s[1][e][i]),max(s[2][e][i],s[3][e][i]))); } return 0; } int main() { int i,n,e; while(scanf("%d",&n)!=EOF) { memset(S,0,sizeof(S)); memset(s,0,sizeof(s)); e=smax=Smax=0; for(i=0;i<n;i++) { e=1-e; scanf("%s",map[e]+1); work(n,e); } if(Smax > smax) { printf("S\n%d\n",Smax); } else if(smax > Smax) { printf("s\n%d\n",smax); } else { printf("?\n%d\n",smax); } } return 0; }