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. MySQL导入大sql 文件大小限制问题的解决

    解决过程如下: 1.由于mysql能解析sql的压缩文件,因此将200M压缩后为5M. 2.默认情况下:MySQL导入文件大小有限制的,最大为2M,所以当文件很大时候,直接无法导入,可修改php.in ...

  2. <Openssl下hash函数>

    hash函数:是不可逆的函数,它的输入可以是任意长度的字节流.它的输出是固定大小的,hash函数的作用就是给你的文件产生一个摘要,它是独一无二的. 例如:y=f(x) x代表输入  y代表输出   输 ...

  3. Java实例学习——企业进销存管理系统(2)

    Java实例学习--企业进销存管理系统(2) (本实例为书上实例,我所记录的是我的学习过程) 开始时间:2月12日 完成时间:暂未完成 2月15日-系统登录 对于昨天新建的12个Java包不能完全显示 ...

  4. iOS书摘之Objective-C编程之道 iOS设计模式解析

    来自<Objective-C编程之道iOS设计模式解析>一书的摘要总结 一.Prototype 原型模式 定义:使用原型实例指定创建对象的种类,并通过复制这个原型创建新的对象.(<设 ...

  5. Android客户端与PC服务端、android服务端通过WiFi通信

    前期准备:我的是Linux Mint操作系统(总之折腾的过程中怀疑过是不是系统的问题),首先是要创建wifi热点给android手机使用,这个时候笔记本作为通信的服务器端,android手机作为客户端 ...

  6. sql单列合并

    有一组这样的数据 1  a  10 2  b  2 4  c  5 1  a  5 在应用中,我们可能需要把出现a的数据合并显示:  1   a   10,5 sqlite上实现:  SELECT   ...

  7. 面向对象(OOP)三

    一.面向对象基础原则 1)单一职责原则(类要写得小而精,低耦合) 内部类 单列模式 对于单一职责原则,其核心思想为:一个类,最好只做一件事,只有一个引起它的变化.单一职责原则可以看做是低耦合.高内聚在 ...

  8. mysql-作业

    一.表关系 请创建如下表,并创建相关约束                 班级表:class       学生表:student       cid caption grade_id   sid sn ...

  9. vue-extend 选项

    vue-extend 选项 mixins 和extend 很相似,但有区别: var extendNews={ //后来的内容用变量接收 updated:function(){ console.log ...

  10. return false;和e.preventDefault;和e.stopPropagation的区别

    因为有父, 子节点同在, 因为有监听事件和浏览器默认动作之分. 使用 JavaScript 时为了达到预期效果经常需要阻止事件和动作执行. 一般我们会用到三种方法, 分别是 stopPropagati ...