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;
}

最新文章

  1. DGV换行操作
  2. 《2016ThoughtWorks技术雷达峰会----变革的原因》
  3. C#线程 在某一时间内,只有N个线程在并发执行,其余都在队列中的实现(转载)
  4. linux:问题
  5. 在线快速生成 CSS Sptite 的网站
  6. C# new用法总结
  7. Python sys.path.append
  8. hyper中安装wdOS-1.0-x86_64(wdlinux)遇到的网卡问题
  9. pl/sql查询中文乱码
  10. latex 常用小结
  11. [51nod1684]子集价值
  12. TensorFlow问题“The TensorFlow library wasn&#39;t compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.”
  13. Spring Boot实现文件下载功能
  14. [20170604]12c Top Frequency histogram补充.txt
  15. React-页面路由参数传递的两种方法
  16. SQL中on条件与where条件的区别
  17. 按某个属性排序(字典序,ascII) js/python
  18. 廖雪峰Java4反射与泛型-2注解-1使用注解
  19. UITableView:改变 TableHeaderView 的高度
  20. ubuntu16.04下笔记本电脑扩展双屏安装过程

热门文章

  1. struts2的执行流程
  2. 在spark2中的shell使用python3
  3. 使用纯css实现波浪效果
  4. [转]vim 快捷键整理
  5. JAXB介绍二
  6. 初学者:Git常用命令总结
  7. iOS核心动画高级技巧之CALayer(一)
  8. IOS PickerView使用
  9. Using Autorelease Pool Blocks
  10. Go - 环境安装