C. Seat Arrangements
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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)

k个人必须连续坐,'.'代表空位,有多少种方法让k个人连续坐下

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <set>
#define debug(a) cout << #a << " = " << a <<endl
using namespace std;
int main() {
int n,m,k,vis[];
while( cin >> n >> m >> k ) {
memset(vis,,sizeof(vis));
int ans = ;
for(int i=;i<n;i++) {
int tmp = ;
for(int j=;j<m;j++) {
char c;
cin >> c;
if( c == '.' ) {
vis[j] ++; //记录每一列连续空位的个数
tmp ++; //记录每一行连续空位的个数
} else { //当此处不为空位时,关于这个空位的行的连续、列的连续均被破坏
vis[j] = ;
tmp = ;
}
if( tmp >= k ) {
ans ++;
}
if( vis[j] >= k && k != ) { //当k为1的时候行的连续与列的连续会重复一次,所以特判k=1
ans ++;
}
}
}
cout << ans << endl;
}
return ;
}

codeforces 919C Seat Arrangements 思维模拟的更多相关文章

  1. Codeforces 919C - Seat Arrangements

    传送门:http://codeforces.com/contest/919/problem/C 给出一张n×m的座位表(有已占座位和空座位),请选择同一行(或列)内连续的k个座位.求选择的方法数. H ...

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

    C. Seat Arrangements time limit per test1 second memory limit per test256 megabytes Problem Descript ...

  3. Codeforces 919 C. Seat Arrangements

    C. Seat Arrangements   time limit per test 1 second memory limit per test 256 megabytes input standa ...

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

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

  5. Codeforces.838D.Airplane Arrangements(思路)

    题目链接 \(Description\) 飞机上有n个位置.有m个乘客入座,每个人会从前门(1)或后门(n)先走到其票上写的位置.若该位置没人,则在这坐下:若该位置有人,则按原方向向前走直到找到空座坐 ...

  6. Codeforces Round #460 (Div. 2)

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

  7. Codeforces Round #243 (Div. 2) B(思维模拟题)

    http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...

  8. Codeforces Round #350 (Div. 2) E 思维模拟

    给出一个合法的括号串 有LRD三种操作 LR分别是左右移动当前位置 且合法 D为删除这个括号和里面的所有 当删除完成后 位置向右移动 如果不能移动 就向左 比赛都是很久远的事情了 写这道题也是一时兴起 ...

  9. Codeforces Round #499 (Div. 2) C. Fly(数学+思维模拟)

    C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

随机推荐

  1. 整理用Java实现数字转化成字符串左边自动补零方法

    Java 中给数字左边补0 (1)方法一 import java.text.NumberFormat; public class NumberFormatTest { public static vo ...

  2. Vue2.0仿饿了么webapp单页面应用

    Vue2.0仿饿了么webapp单页面应用 声明: 代码源于 黄轶老师在慕课网上的教学视频,我自己用vue2.0重写了该项目,喜欢的同学可以去支持老师的课程:http://coding.imooc.c ...

  3. 【Java例题】1.2计算n的m次方

    package study; import java.util.*; import java.math.*; public class study { public static void main( ...

  4. 【数据结构学习】关于HashMap的那些事儿

    涉及数据结构 红黑树 链表 哈希 从CRUD说起 预热知识: DEFAULT_INITIAL_CAPACITY = 1 << 4, HashMap默认容量为16(n << m意 ...

  5. java并发编程(二十三)----(JUC集合)ConcurrentSkipListMap介绍

    ConcurrentSkipListMap提供了一种线程安全的并发访问的排序映射表.内部是SkipList(跳表)结构实现,在理论上能够在O(log(n))时间内完成查找.插入.删除操作. 理解Ski ...

  6. 如何使用dmidecode命令查看硬件信息

    引言 当我们需要获取机器硬件信息时,可使用linux系统自带的dmidecode工具进行查询. dmidecode命令通过读取系统DMI表,显示服务器硬件和BIOS信息.除了可使用dmidecode查 ...

  7. JVM调优之经验

    在生产系统中,高吞吐和低延迟一直都是JVM调优的最终目标,但这两者恰恰又是相悖的,鱼和熊掌不可兼得,所以在调优之前要清楚舍谁而取谁.一般计算任务和组件服务会偏向高吞吐,而web展示则偏向低延迟才会带来 ...

  8. 优雅的在WinForm/WPF/控制台 中使用特性封装WebApi

    优雅的在WinForm/WPF/控制台 中使用特性封装WebApi 说明 在C/S端作为Server,建立HTTP请求,方便快捷. 1.使用到的类库 Newtonsoft.dll 2.封装 HttpL ...

  9. 世纪龙校招java开发一、二面 面经

    头一天做的笔试,涉及到计组基本知识,还有几道智力题.java部分很简单(真的很简单有点基础就划过了) 第二天收简历 在隔壁教室等 叫到你 你就去面试 一面:先自我介绍 1 == 和 equals区别( ...

  10. c语言实现基本的数据结构(一) 线性表

    #include <stdio.h> #include <tchar.h> #include <stdlib.h> #define LIST_INIT_SIZE 1 ...