codeforces 919C Seat Arrangements 思维模拟
1 second
256 megabytes
standard input
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.
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.
A single number, denoting the number of ways to find k empty seats in the same row or column.
2 3 2
**.
...
3
1 2 2
..
1
3 3 4
.*.
*.*
.*.
0
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)
k个人必须连续坐,'.'代表空位,有多少种方法让k个人连续坐下
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <set>
#define debug(a) cout << #a << " = " << a <<endl
using namespace std;
int main() {
int n,m,k,vis[];
while( cin >> n >> m >> k ) {
memset(vis,,sizeof(vis));
int ans = ;
for(int i=;i<n;i++) {
int tmp = ;
for(int j=;j<m;j++) {
char c;
cin >> c;
if( c == '.' ) {
vis[j] ++; //记录每一列连续空位的个数
tmp ++; //记录每一行连续空位的个数
} else { //当此处不为空位时,关于这个空位的行的连续、列的连续均被破坏
vis[j] = ;
tmp = ;
}
if( tmp >= k ) {
ans ++;
}
if( vis[j] >= k && k != ) { //当k为1的时候行的连续与列的连续会重复一次,所以特判k=1
ans ++;
}
}
}
cout << ans << endl;
}
return ;
}
codeforces 919C Seat Arrangements 思维模拟的更多相关文章
- Codeforces 919C - Seat Arrangements
传送门:http://codeforces.com/contest/919/problem/C 给出一张n×m的座位表(有已占座位和空座位),请选择同一行(或列)内连续的k个座位.求选择的方法数. H ...
- 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 Round #243 (Div. 2) B(思维模拟题)
http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...
- Codeforces Round #350 (Div. 2) E 思维模拟
给出一个合法的括号串 有LRD三种操作 LR分别是左右移动当前位置 且合法 D为删除这个括号和里面的所有 当删除完成后 位置向右移动 如果不能移动 就向左 比赛都是很久远的事情了 写这道题也是一时兴起 ...
- Codeforces Round #499 (Div. 2) C. Fly(数学+思维模拟)
C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
随机推荐
- 语音控制单片机工作【百度语音识别,串口发送数据到单片机】【pyqt源码+软件】!!
前些天闲着没事,就做了个语音识别结合串口发送指令的软件,用的是pyqt写的,软件打开后对着笔记本的话筒说话, 他就能识别返回文字结果,然后匹配语音中的关键词,如果有关键词就发送关键词对应的命令,比如语 ...
- wpf界面按钮自动点击
Button Button = new Button();Button.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));//在按钮生成时便会自动触 ...
- 理解nodejs中的stream(流)
阅读目录 一:nodeJS中的stream(流)的概念及作用? 二:fs.createReadStream() 可读流 三:fs.createWriteStream() 可写流 回到顶部 一:node ...
- Java虚拟机(二)-对象创建
这一篇大致说明一下,对象在Java堆中对象分配.内存布局以及访问定位 1.对象的创建 虚拟机在遇到一条new指令时,首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用,并且检查这个符号引 ...
- STL 队列
头文件 #include <queue> 定义 普通队列: queue < int > q; 优先队列: priority_queue < int, vector< ...
- 编程使用c#连接到IBM db2的两种方式
一:使用c#通过odbc连接到IBM db2使用 ConnectionString 属性连接到各种数据源. 部署:只要在客户端安装IBM DB2 ODBC driver.配置DSn即可. 1):可以单 ...
- DNS解析综合学习案例
DNS解析综合学习案例 #图右侧为做题前环境配置 #命令为红色 #命令加载内容为绿色 #vi编辑内容为蓝色 1.用户需把/dev/myvg/mylv逻辑卷以支持磁盘配额的方式挂载到网页目录下 [roo ...
- Netty源码分析--内存模型(下)(十二)
这一节我们一起看下分配过程 PooledByteBuf<T> allocate(PoolThreadCache cache, int reqCapacity, int maxCapacit ...
- pickle 基础用法
def save_obj_to_file(path, target_obj): file = open(path,'wb') pickle.dump(target_obj) file.close() ...
- Linux 目录递归赋权,解决 Linux权限不够
如你要操作一个目录下的文件时,系统提示 “权限不够”,可用以下方法解决. 如 test 文件目录. 1.用root账号登陆系统. 2.输入如下命令: chmod 777 test -R 这样访问.修改 ...