传送门: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. iOS开发基础:OC数组对象NSArray的常用方法

    本文介绍了OC的数组对象的基本方法的使用: 因为OC的数组中存储的为对象类型,所以我们可以新建一个Person类,通过Person生成对象进行操作. 其中Person.h中的代码为: [objc] v ...

  2. 简单动态规划——最长公共子序列&&最长回文子序列&&最长上升||下降子序列

    最长公共子序列,顾名思义当然是求两个字符串的最长公共子序列啦,当然,这只是一道非常菜的动规,所以直接附上代码: #include<iostream> #include<cstdio& ...

  3. (函数即服务)Faas的现状与未来

    刚看到jolestar一位从法律转行程序员的前辈写了一篇Faas现状与未来的文章,里面很多观点都很有启发,或许正如他说的那样,由于Faas能较好的解决资源利用率和开发效率问题,2018年Faas将变得 ...

  4. bzoj3398 [Usaco2009 Feb]Bullcow 牡牛和牝牛——递推 / 组合数

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3398 对于这种有点巧妙的递推还是总是没有思路... 设计一个状态 f[i] 表示第 i 位置 ...

  5. bzoj1977 [BeiJing2010组队]次小生成树 Tree——严格次小生成树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1977 因为严格,所以要记录到 LCA 的一个次小值: 很快写好,然后改掉一堆错误后终于过了样 ...

  6. IDEA Spark Streaming Flume数据源 --解决无法转化为实际输入数据,及中文乱码(Scala)

    需要三步: 1.shell:往 1234 端口写数据 nc localhost 1234 2.shell: 启动flume服务 cd /usr/local2/flume/bin ./flume-ng ...

  7. Treap(模板)

    人生第一次平衡树,Treap板子 #include<iostream> #include<cstdio> #include<cstring> #include< ...

  8. [Swift通天遁地]四、网络和线程-(10)处理图片:压缩、缩放、圆角、CoreImage滤镜、缓存

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

  9. [python] ThreadPoolExecutor线程池

    初识 Python中已经有了threading模块,为什么还需要线程池呢,线程池又是什么东西呢?在介绍线程同步的信号量机制的时候,举得例子是爬虫的例子,需要控制同时爬取的线程数,例子中创建了20个线程 ...

  10. 在下载jar包时,要有三个包,分别为使用的把class、查看文档的api、查看源代码的资源包

    字节码包: spring-webmvc-4.1.6.RELEASE.jar 文档包:    spring-webmvc-4.1.6.RELEASE-javadoc.jar 资源包:    webmvc ...