传送门: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. The Open Graph protocol

    https://www.quora.com/What-does-this-tag-mean-html-lang-en-US-prefix-og-http-ogp-me-ns https://stack ...

  2. ubuntu16.04安装flash player

    ubuntu16.04安装flash player sudo apt-get install flashplugin-installer 1 2019: apt-get install browser ...

  3. 安装nghttp2 报错error: Libtool library used but 'LIBTOOL' is undefined

    nghttp2 报错error: Libtool library used but ‘LIBTOOL‘ is undefined 如果重新安装libtool和autoconf升级到2.69后,还是报错 ...

  4. openstack service glance-api/registry mysql of max_connection

  5. 网页分享URL

    <a href="tencent://Message/?Uin=QQ号码&Site=qq联系">点击联系</a> 1.新浪微博:<a href ...

  6. Django day32 跨域问题,创建vue项目,axios的使用

    一:跨域问题 1.同源策略(浏览器的安全策略) 只允许当前页面朝当前域下发请求,如果向其他域发请求,请求可以正常发送,数据也可以拿回,但是被浏览器拦截了 2.cors:只要服务器实现了CORS,就可以 ...

  7. 哈夫曼编码译码系统(c/c++)

    哈夫曼编码译码系统的实现,主要包含三部分: 1.创建哈夫曼树 2.编码函数 3.译码函数 编写代码时为了方便,在这里混用了c++的输入输出流.主体用c语言实现. 下面时代码部分: 1.头文件,以及储存 ...

  8. 如何获得Windows聚焦壁纸0726

    Windows聚焦壁纸缓存位置,绿色部分是你的用户名: (1)找到之后,一般是大于100K的 (2)将图片复制到另一个文件夹img,要用到路径 (3)在改文件夹下新建一个txt; txt文档里写:re ...

  9. RabbitMQ~一些术语和最消息的生产

    学习一种技术需要先了解它,而想要学好一种技术,需要更多的了解它的组成,原理和实现机制! RabbitMQ安装介绍 RabbitMQ是由erlang语言开发的,所以必须先有安装erlang,类似java ...

  10. Unity Android交互过坑指南

    Unity Android交互过坑指南 介于网上看过很多unity和Android交互的教程,都或多或少的漏掉了一些部分,导致编译过程中出现各种问题,特此整理一份教程,仅供参考 介绍 本次实现的是在游 ...