Codeforces 919C - Seat Arrangements
传送门: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的更多相关文章
- codeforces 919C Seat Arrangements 思维模拟
C. Seat Arrangements time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #460 (Div. 2)-C. Seat Arrangements
C. Seat Arrangements time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- Codeforces 919 C. Seat Arrangements
C. Seat Arrangements time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 【Codeforces Round #460 (Div. 2) C】 Seat Arrangements
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用pre[i][j]表示第i行前j列的和. 然后枚举连续座位的最左上点. (有两种可能向右或向下k个. 则还需要处理出pre2[i] ...
- Codeforces.838D.Airplane Arrangements(思路)
题目链接 \(Description\) 飞机上有n个位置.有m个乘客入座,每个人会从前门(1)或后门(n)先走到其票上写的位置.若该位置没人,则在这坐下:若该位置有人,则按原方向向前走直到找到空座坐 ...
- Codeforces Round #460 (Div. 2)
A. Supermarket We often go to supermarkets to buy some fruits or vegetables, and on the tag there pr ...
- Codeforces Gym 100463E Spies 并查集
Spies Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Desc ...
- 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 ...
- 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 ...
随机推荐
- YTU 2760: 字符串---首字母变大写
2760: 字符串---首字母变大写 时间限制: 1 Sec 内存限制: 128 MB 提交: 343 解决: 136 题目描述 输入一行英文句子,将每个单词的第一个字母改成大写字母. 输入 一个 ...
- js如何获取某id的子标签
思路:根据id获取父对象,然后使用childNodes获取所有子对象数组,关键代码: document.getElementById(div_id).childNodes; // 子对象数组 实例 ...
- CodeForces - 556D
D. Case of Fugitive time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- [Codeforces 489E] Nastya and King-Shamans
[题目链接] http://codeforces.com/contest/992/problem/E [算法] 线段树 + 二分 时间复杂度 : O(NlogN^2) [代码] #include< ...
- 2017 nodeJS
一.版本迅速更新 Chrome浏览器已经蹦到57版本了,是名副其实的版本帝,作为兄弟的Node.js也一样,1.0之前等了6年,而从1.0到8.0,只用了2年时间,现在已到9以上了 我们就数一下 从v ...
- 【转载】深入理解Linux文件系统
1.rm-rf删除目录里的文件后,为什么可以恢复? 首先创建一个空目录test,目录的blocksize为4096字节 为了空目录还是4096?首先,目录的大小取决它所包含的文件的inode(访问 ...
- E20170926-mk
validation n. 确认; proposal n. 建议; 提议; 求婚; 〈美〉投标; teaser n. 戏弄者,喜欢戏弄别人的人; 棘手的问题; batch n. 一批; 一 ...
- ACM_ZHANGZHANG喜欢手表
ZHANGZHANG喜欢手表 Time Limit: 2000/1000ms (Java/Others) Problem Description: ZHANGZHANG刚过生日,收到了好朋友NENGN ...
- 通过Oracle透明网关连接Sybase
Oracle公司提出的透明网关技术可用于实现与其他多种类型的数据库的互联,实现不同类型数据之间建立连接,方便于使用者进行查询.近日,在公司的某项目的实施过程中,开发人员需要访问Sybase数据库中的某 ...
- C# asp.net repeater实现排序功能,自动排序,点击头部排序,点击列排序
在网上看到好多关于repeater排序的,自己动手用了,发现一些问题,贴源码后把发现的问题以及解决方法给出 repeater实现排序功能(单击升序排列,再单击降序排列).原理很简单,在<TD&g ...