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)

这个题,特判1那里hack一堆人,改了就可以,不用搜索,直接暴力就可以。

代码:

 1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 #include<algorithm>
5 #include<cmath>
6 #include<queue>
7 #include<map>
8 using namespace std;
9 const int maxn=1e4+5;
10 const double eps=1e6;
11 const int inf=1<<30;
12 char s[maxn][maxn];
13 int main(){
14 int n,m,k;
15 ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
16 while(cin>>n>>m>>k){
17 memset(s,0,sizeof(s));
18 for(int i=1;i<=n;i++)
19 cin>>s[i];
20 int ans=0,l=0;
21 for(int i=1;i<=n;i++){
22 l=0;
23 for(int j=0;j<=m-1;j++){
24 if(s[i][j]=='.')l++;
25 else{
26 ans+=max(0,l-k+1);
27 l=0;
28 }
29 if(j==(m-1)&&s[i][j]!='*')
30 ans+=max(0,l-k+1);
31 }
32 }
33 for(int j=0;j<=m-1;j++){
34 l=0;
35 for(int i=1;i<=n;i++){
36 if(s[i][j]=='.') l++;
37 else{
38 ans+=max(0,l-k+1);
39 l=0;
40 }
41 if(i==n&&s[i][j]!='*')
42 ans+=max(0,l-k+1);
43 }
44 }
45 if(k==1) ans/=2;
46 cout<<ans<<endl;
47 }
48 }

Codeforces 919 C. Seat Arrangements的更多相关文章

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

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

  2. codeforces 919C Seat Arrangements 思维模拟

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

  3. Codeforces 919C - Seat Arrangements

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

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

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

  5. Codeforces 919 E Congruence Equation

    题目描述 Given an integer xx . Your task is to find out how many positive integers nn ( 1<=n<=x1&l ...

  6. Codeforces 919 D Substring

    题目描述 You are given a graph with nn nodes and mm directed edges. One lowercase letter is assigned to ...

  7. Codeforces 919 B. Perfect Number

      B. Perfect Number   time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  8. Codeforces 919 A. Supermarket

    这场cf有点意思,hack场,C题等于1的特判hack很多人(我hack成功3个人,上分了,哈哈哈,咳咳...) D题好像是树形dp,E题好像是中国剩余定理,F题好像还是dp,具体的不清楚,最近dp的 ...

  9. Codeforces 919 行+列前缀和 树上记忆化搜索(树形DP)

    A B C #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) ...

随机推荐

  1. CSS基础:block,inline和inline-block

    css的display属性是前端开发中非常常见的属性,本文简单介绍下其中比较常用的属性值,即block.inline和inline-block. HTML组件中呈现一片空白区域的组件都可当盒模型(bo ...

  2. destoon 支付异步接口文件 notify.php 调试方式

    在if($verify_result) { 之前复制这三个变量 就可以直接访问notify.php 启用调试模式 或者 逐步echo 相关变量来调试 错误原因   notify.php没有入口文件 是 ...

  3. paper:synthesizable finite state machine design techniques using the new systemverilog 3.0 enhancements 之 standard verilog FSM conding styles(二段式)

    1.Two always block style with combinational outputs(Good Style) 对应的代码如下: 2段式总结: (1)the combinational ...

  4. 【windows】【md5】查看文件的md5值

    certutil -hashfile filename MD5 certutil -hashfile filename SHA1 certutil -hashfile filename SHA256 ...

  5. leetcode-18-remove

    283. Move Zeroes 解题思路: 从nums[0]开始,如果是零就和它后面的第一个非零数交换,不是零就下一位.不贴代码了,比较简单. 27. Remove Element 解题思路: 这道 ...

  6. python模块之shutil和zipfile

    shutil 模块 高级的 文件.文件夹.压缩包 处理模块 shutil.copyfileobj(fsrc, fdst[, length])将文件内容拷贝到另一个文件中 import shutil s ...

  7. 牛客网暑期ACM多校训练营(第七场)A Minimum Cost Perfect Matching(找规律)

    题意: 给定n, 求一个0~n-1的全排列p, 使得的和最小 分析: 打表发现最优解肯定是和为0的, 然后如果为2的幂就是直接反转即可, 不然的话就要分开从前面到后面逐步拆分, 具体思想模拟一下n = ...

  8. Java策略模式(Strategy)

    一.定义 定义一组算法,将每个算法都封装起来,并且使它们之间可以互换.策略模式使这些算法在客户端调用它们的时候能够互不影响地变化.(Java的TreeSet集合中,构造方法可传入具体的比较器对象以实现 ...

  9. 查找最小的k个元素 【微软面试100题 第五题】

    题目要求: 输入n个整数,输出其中最小的k个. 例如:输入1,2,3,4,5,6,7,8这8个数字,则最小的4个数字为1,2,3,4. 参考资料:剑指offer第30题. 题目分析: 解法一: 用快排 ...

  10. ogre3D学习基础8 --- 资源管理器

    资源管理 可管理的资源有: 材质资源:在.material文件中包含的材质脚本定义(技术.通路.纹理单元等数据的定义). 模型资源:经过优化的二进制网格模型文件,扩展名为.mesh.包含几何信息和一些 ...