【Codeforces Round #460 (Div. 2) C - Seat Arrangements】(模拟)

链接: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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值