今天就做做单调栈,挺好写的。应该多了解了原理
字符串读入还是有问题啊,这个不行,得看清楚输入后在写!
一次AC:
#include<stdio.h>
#include<string.h>
#include<math.h>
int n,m,ans;
int a[1005],stack[1005],pos[1005];
int GetAns()
{
int i,top;
top=0;
stack[0]=pos[0]=0;
for (i=1;i<=n ;i++ )
{
while (top>0&&a[i]<=stack[top])
{
if (ans<(i-1-pos[top-1])*stack[top])
ans=(i-1-pos[top-1])*stack[top];
top--;
}
top++;
stack[top]=a[i];
pos[top]=i;
}
while (top>0)
{
if (ans<(n-pos[top-1])*stack[top])
ans=(n-pos[top-1])*stack[top];
top--;
}
}
int main()
{
int cas,i,j;
char ch[2];
scanf("%d",&cas);
while (cas--)
{
memset(a,0,sizeof(a));
ans=0;
scanf("%d%d",&m,&n);
for (i=0;i<m ;i++ )
{
for (j=1;j<=n ;j++ )
{
scanf("%s",&ch);
if (ch[0]=='F')
a[j]++;
else
a[j]=0;
}
GetAns();
}
printf("%d\n",3*ans);
}
return 0;
}
加油啊,加油!