盖房子
#include<cstdio>
using namespace std;
int N,M;
int Ans;
int F[1010][1010];
inline int min(int x,int y,int z)
{
if(x>y) x=y; if(x>z) x=z;
return x;
}
int main()
{
scanf("%d%d",&N,&M);
Ans=0;
for(int i=1;i<=N;++i)
for(int j=1;j<=M;++j){
int a; scanf("%d",&a);
if(a){
F[i][j]=min(F[i-1][j],F[i][j-1],F[i-1][j-1])+1;
if(F[i][j]>Ans) Ans=F[i][j];
}
else F[i][j]=0;
}
printf("%d\n",Ans);
return 0;
}
迎春舞会之集体舞
#include<cstdio>
#include<cstring>
using namespace std;
int N;
int L,Ans;
char s[200];
int F[200][200];
bool bo[200][200];
inline int min(int x,int y,int z)
{
if(x>y) x=y; if(x>z) x=z;
return x;
}
int main()
{
scanf("%d",&N);
memset(bo,0,sizeof(bo));
for(int i=1;i<=N;++i){
scanf("%s",s);
for(int j=i;j<=i+2*(N-i+1)-2;++j)
if(s[j-i]=='-')
bo[i][j]=1;
}
memset(F,0,sizeof(F)); L=0;
for(int i=1;i<=N;++i){
for(int j=i;j<=i+2*(N-i+1)-2;++j)
if(bo[i][j]){
F[i][j]=min(F[i-1][j-1],F[i-1][j],F[i-1][j+1])+1;
if((j-i+1)&1&&F[i][j]>L) L=F[i][j];
}
}
Ans=0;
for(int i=1;i<=L;++i)
Ans+=i+(i-1);
printf("%d\n",Ans);
return 0;
}
三角形
#include<cstdio>
#include<cstring>
using namespace std;
typedef int Arr[110][110];
int N;
int tot;
Arr a,f,g;
int cc[26];
int Ans[26];
char s[101];
inline int min(int x,int y)
{ return x>y?y:x; }
inline int min(int x,int y,int z)
{
if(x>y) x=y; if(x>z) x=z;
return x;
}
void turn(Arr &a)
{
Arr b;
for(int i=1;i<=N;++i)
for(int j=1;j<=N;++j)
b[i][j]=a[N-j+1][i];
memcpy(a,b,sizeof(a));
}
int main()
{
scanf("%d",&N);
memset(a,-1,sizeof(a));
for(int i=1;i<=N;++i){
scanf("%s",s);
for(int j=1;j<=N;++j){
a[i][j]=s[j-1]-'A';
cc[a[i][j]]=1;
}
}
tot=0;
for(int k=1;k<=4;++k){
memset(f,0,sizeof(f));
memset(g,0,sizeof(g));
for(int i=1;i<=N;++i)
for(int j=1;j<=N;++j){
if(a[i-1][j]==a[i][j]&&a[i][j-1]==a[i][j])
f[i][j]=min(f[i-1][j],f[i][j-1])+1;
else f[i][j]=1;
Ans[a[i][j]]+=f[i][j]-1;
tot+=f[i][j]-1;
if(a[i-1][j-1]==a[i][j]&&a[i-1][j]==a[i][j]&&a[i-1][j+1]==a[i][j])
g[i][j]=min(g[i-1][j-1],g[i-1][j],g[i-1][j+1])+1;
else g[i][j]=1;
Ans[a[i][j]]+=g[i][j]-1;
tot+=g[i][j]-1;
}
if(k!=4) turn(a);
}
printf("%d\n",tot);
for(int i=0;i<26;++i)
if(cc[i])
printf("%c %d\n",i+'A',Ans[i]);
return 0;
}
posted on 2009-08-13 09:05
xfstart07 阅读(136)
评论(0) 编辑 收藏 引用