C. Seat Arrangements

time limit per test1 second

memory limit per test256 megabytes

Problem Description

Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of the seats were occupied.

The classroom contains n rows of seats and there are m seats in each row. Then the classroom can be represented as an n × m matrix. The character ‘.’ represents an empty seat, while ‘*’ means that the seat is occupied. You need to find k consecutive empty seats in the same row or column and arrange those seats for you and your friends. Your task is to find the number of ways to arrange the seats. Two ways are considered different if sets of places that students occupy differs.

Input

The first line contains three positive integers n, m, k (1 ≤ n, m, k ≤ 2 000), where n, m represent the sizes of the classroom and k is the number of consecutive seats you need to find.

Each of the next n lines contains m characters ‘.’ or ‘‘. They form a matrix representing the classroom, ‘.’ denotes an empty seat, and ‘’ denotes an occupied seat.

Output

A single number, denoting the number of ways to find k empty seats in the same row or column.

Examples

input

2 3 2

**.



output

3

input

1 2 2

..

output

1

input

3 3 4

.*.

.

.*.

output

0

Note

In the first sample, there are three ways to arrange those seats. You can take the following seats for your arrangement.

(1, 3), (2, 3)

(2, 2), (2, 3)

(2, 1), (2, 2)


解题心得:

  1. 题意就是说,在同一行或者同一列中要找k个连续的空地,有多少种找法。
  2. 思路是先找每一行,将连续的空地加起来,如果大于等于k个,就用连续空地数-k+1,先将所有的行找出来,再将所有的列找出来。就这个思路,被hack了很多次,就是处理k==1的问题啊。第一次被hack,想将列中重复找的k==1给除去,然后又被hack,没除完,最后k==1直接特判一个一个 的数空地就过了。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2010;
char maps[maxn][maxn];
int n,m,k;
long long ans = 0; void init()
{
for(int i=0;i<n;i++)
scanf("%s",maps[i]);
} void check_row()//找每一行中的连续空地数目
{
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(maps[i][j] == '.')
{
int z = j+1;
int tot = 1;
while(maps[i][z] == '.')
{
tot++;
z++;
}
if(tot >= k)
ans += tot-k+1;
j = z-1;
}
} void check_col()//找每一列中的连续的空地数目
{
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
if(maps[j][i] == '.')
{
int z = j+1;
int tot = 1;
while(maps[z][i] == '.')
{
z++;
tot++;
}
if(tot == 1)
continue;
if(tot >= k)
ans += tot-k+1;
j = z-1;
}
} void special_judge(){//特判k==1的时候的方案数
int ans = 0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(maps[i][j] == '.')
ans++;
printf("%d\n",ans);
} int main()
{
scanf("%d%d%d",&n,&m,&k);
init();
if(k == 1){
special_judge();
return 0;
}
check_row();
check_col();
printf("%lld\n",ans);
return 0;
}

Codeforces Round #460 (Div. 2)-C. Seat Arrangements的更多相关文章

  1. Codeforces Round #460 (Div. 2)

    A. Supermarket We often go to supermarkets to buy some fruits or vegetables, and on the tag there pr ...

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

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用pre[i][j]表示第i行前j列的和. 然后枚举连续座位的最左上点. (有两种可能向右或向下k个. 则还需要处理出pre2[i] ...

  3. Codeforces Round #460 (Div. 2) ABCDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. ...

  4. [Codeforces]Codeforces Round #460 (Div. 2)

    Supermarket 找最便宜的就行 Solution Perfect Number 暴力做 Solution Seat Arrangement 注意当k=1时,横着和竖着是同一种方案 Soluti ...

  5. Codeforces Round #460 (Div. 2) E. Congruence Equation (CRT+数论)

    题目链接: http://codeforces.com/problemset/problem/919/E 题意: 让你求满足 \(na^n\equiv b \pmod p\) 的 \(n\) 的个数. ...

  6. Codeforces Round #460 (Div. 2) 前三题

    Problem A:题目传送门 题目大意:给你N家店,每家店有不同的价格卖苹果,ai元bi斤,那么这家的苹果就是ai/bi元一斤,你要买M斤,问最少花多少元. 题解:贪心,找最小的ai/bi. #in ...

  7. Codeforces Round #460 (Div. 2): D. Substring(DAG+DP+判环)

    D. Substring time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #460 (Div. 2).E 费马小定理+中国剩余定理

    E. Congruence Equation time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

  9. Codeforces Round #460 (Div. 2)-D. Substring

    D. Substring time limit per test3 seconds memory limit per test256 megabytes Problem Description You ...

随机推荐

  1. springBoot jpa uuid生成策略

    实体类 import org.hibernate.annotations.GenericGenerator; import javax.persistence.*; @Entity @Table(na ...

  2. js为页面元素添加水印

    近期有需求为页面部分区域添加上水印,通过在网上找到了js为页面添加水印的方法,后来经过自己的改进,可以实现为页面部分元素添加水印,最终效果如下图: 代码如下: function watermark(s ...

  3. 【干货】JavaScript DOM编程艺术学习笔记4-6

    四.案例研究:JavaScript图片库 js: function showPic(whichpic){ //取得链接 var source=whichpic.getAttribute("h ...

  4. linux修改系统时间为北京时间(CentOS)

    删除本地时间 rm -rf /etc/localtime 设置时区为上海 ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 利用date查看 ...

  5. 解决perl: warning: Setting locale failed.

    在Ubuntu Server 12.04上执行apt-get install命令时,报如下warning   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

  6. SAP Cloud for Customer Extensibility的设计与实现

    今天的文章来自Jerry的同事,SAP成都研究院C4C开发团队的开发人员徐欢(Xu Boris).徐欢就坐我左手边的位置,因此我工作中但凡遇到C4C的技术问题,一扭头就可以请教他了,非常方便.下图是他 ...

  7. iOS开发学习之大牛们的博客

    http://blog.csdn.net/iosbird/article/details/51981023 唐巧:http://blog.devtang.com/blog/archives/ 王巍:h ...

  8. 2017.12.13 Java中是怎样通过类名,创建一个这个类的数组

    先在类方法中定义数组的方法: public int[] method6(int[] arr){ for(int i = 0; i<arr.length;i++){ arr[i] = (int)( ...

  9. 机器学习_线性回归和逻辑回归_案例实战:Python实现逻辑回归与梯度下降策略_项目实战:使用逻辑回归判断信用卡欺诈检测

    线性回归: 注:为偏置项,这一项的x的值假设为[1,1,1,1,1....] 注:为使似然函数越大,则需要最小二乘法函数越小越好 线性回归中为什么选用平方和作为误差函数?假设模型结果与测量值 误差满足 ...

  10. windows下安装php依赖关系管理工具composer

    1.安装Composer Composer是PHP的依赖管理工具之一,官方网站 http://getcomposer.org/ .它支持多种安装方式,对于在win下做开发的草来说,最便捷的方式就是下载 ...