题目链接
https://vjudge.net/problem/CodeForces-919C
题意
n排m列的位置,要找连续的k排或者k列座位,问有多少种。
思路
先一排一排搜,再一列一列搜。
如果k = 1的话,上述方法会重复计算两边。
AC代码
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<string>
#include<sstream>
#include<cctype>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const double PI=atan(1.0)*4;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1000000007;
const int maxn = 2010;
char a[maxn][maxn];
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, m, k, x, ans = 0;
scanf("%d%d%d", &n, &m, &k);
for(int i = 0; i < n; i++)
{
scanf("%s", a[i]);
x = 0;
for(int j = 0; j < m; j++)
{
if(a[i][j] == '.')
x++;
else
{
if(x >= k)
ans = ans + x - k + 1;
x = 0;
}
}
if(x >= k)
ans = ans + x - k + 1;
}
if(k != 1)
{
for(int j = 0; j < m; j++)
{
x = 0;
for(int i = 0; i < n; i++)
{
if(a[i][j] == '.')
x++;
else
{
if(x >= k)
ans = ans + x - k + 1;
x = 0;
}
}
if(x >= k)
ans = ans + x - k + 1;
}
}
printf("%d\n", ans);
return 0;
}