传送门:http://codeforces.com/contest/919/problem/C

给出一张n×m的座位表(有已占座位和空座位),请选择同一行(或列)内连续的k个座位。求选择的方法数。

Hack:首先,若k=1,则所有的空座位均可选,方法数即为空座位数。

对于某一行(或列)中连续的len个座位,选择的方法数为len-k+1。

于是,分别逐行、逐列地统计,求出答案。参考程序如下:

#include <stdio.h>
#define MAX_N 2000 char map[MAX_N][MAX_N];
int row[MAX_N][MAX_N], col[MAX_N][MAX_N]; int main(void)
{
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for (int i = ; i < n; i++) {
getchar();
for (int j = ; j < m; j++)
map[i][j] = getchar();
}
int ans = ;
if (k == ) {
for (int i = ; i < n; i++) {
for (int j = ; j < m; j++)
if (map[i][j] == '.') ans++;
}
printf("%d\n", ans);
return ;
}
//pass by row
for (int i = ; i < n; i++) {
int len = , cnt = ;
for (int j = ; j < m; j++) {
if (map[i][j] == '*') {
if (len) row[i][cnt++] = len;
len = ;
}
else len++;
}
if (len) row[i][cnt++] = len;
}
//pass by column
for (int j = ; j < m; j++) {
int len = , cnt = ;
for (int i = ; i < n; i++) {
if (map[i][j] == '*') {
if (len) col[j][cnt++] = len;
len = ;
}
else len++;
}
if (len) col[j][cnt++] = len;
}
for (int i = ; i < n; i++) {
for (int j = ; row[i][j] != ; j++)
if (row[i][j] >= k) ans += row[i][j] - k + ;
}
for (int i = ; i < m; i++) {
for (int j = ; col[i][j] != ; j++)
if (col[i][j] >= k) ans += col[i][j] - k + ;
}
printf("%d\n", ans);
return ;
}

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

  1. codeforces 919C Seat Arrangements 思维模拟

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

  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 Gym 100463E Spies 并查集

    Spies Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Desc ...

  8. Codeforces 725B Food on the Plane

    B. Food on the Plane time limit per test:2 seconds memory limit per test:256 megabytes input:standar ...

  9. Codeforces 839B Game of the Rows【贪心】

    B. Game of the Rows time limit per test:1 second memory limit per test:256 megabytes input:standard ...

随机推荐

  1. Codesys——限定符的使用方法[来自Codesys的Help]

    Qualifier for actions in SFC In order to configure in which way the actions should be associated to ...

  2. java线程系列---Runnable和Thread的区别 (转载)

    转自:http://blog.csdn.net/wwww1988600/article/details/7309070 在java中可有两种方式实现多线程,一种是继承 Thread类,一种是实现Run ...

  3. tinymce 出现 Uncaught (in promise) TypeError: ae(...).createObjectURL is not a function

    需要引入两个JS文件:jQuery.tinymce.min.js 和 tinymce.min.js <script type="text/javascript" src=&q ...

  4. cookie封装函数(添加,获取,删除)

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  5. window.onload的使用

    window.onload:当页面加载的时候可以调用某些函数 例如: 1.最简单的调用方式 直接写到html的body标签里面,如: <html> <body onload=&quo ...

  6. [Swift通天遁地]七、数据与安全-(5)高效操作SQLite数据库

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. Django day27 认证组件,权限组件()

    一:认证组件 1.写一个类 class LoginAuth(): # 函数名一定要叫authenticate,接收必须两个参数,第二个参数是request对象 def authenticate(sel ...

  8. 【转】深入理解Java多态原理

    之前一直知道多态是什么东西,平时敲代码也经常用到多态,但一直没有真正了解多态底层的运行机制到底是怎么样的,这两天才研究明白点,特地写下来,跟各位同学一起进步,同时也希望各位大神指导和指正. 多态的概念 ...

  9. 题解报告:hdu 3790 最短路径问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3790 Problem Description 给你n个点,m条无向边,每条边都有长度d和花费p,给你起 ...

  10. 检查阿里云ssl证书到期情况

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019-06-10 16:00 # @Author : Anthony.long # ...