链接:http://codeforces.com/contest/919/problem/C
题意:给定n*m的矩形,只由’*’ 和’.’组成,’.’代表空座,问能找到多少种连续(只能是横着或者竖着)的k个座位的方案?
分析: 模拟 或者前缀和
注意:k=1时这种情况
暴力。 事实证明我需要学习暴力, 暴力的姿势。。
复杂度O(n^2)
代码:
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e8;
const int N=2e3+5;
const ll maxn=1LL<<60;
const int dir[4][2]= {-1,0,1,0,0,-1,0,1};
char a[N][N];
int n,m,k;
int cnt,ans;
void init()
{
ans=0;
}
void solve()
{
rep(j,0,m)
{
cnt=0;
rep(i,0,n)
{
if(a[i][j]=='.') cnt++;
else cnt=0;
if(cnt>=k) ans++;
}
}
}
int main()
{
while(~scanf("%d%d%d",&n,&m,&k))
{
init();
rep(i,0,n)
{
cnt=0;
scanf("%s",a[i]);
rep(j,0,m)
{
if(a[i][j]=='.') cnt++;
else cnt=0;
if(cnt>=k) ans++;
}
}
if(k>1) solve();
printf("%d\n",ans);
}
return 0;
}