Codeforces 919 C. 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)
这个题,特判1那里hack一堆人,改了就可以,不用搜索,直接暴力就可以。
代码:
1 #include<iostream>
2 #include<cstring>
3 #include<cstdio>
4 #include<algorithm>
5 #include<cmath>
6 #include<queue>
7 #include<map>
8 using namespace std;
9 const int maxn=1e4+5;
10 const double eps=1e6;
11 const int inf=1<<30;
12 char s[maxn][maxn];
13 int main(){
14 int n,m,k;
15 ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
16 while(cin>>n>>m>>k){
17 memset(s,0,sizeof(s));
18 for(int i=1;i<=n;i++)
19 cin>>s[i];
20 int ans=0,l=0;
21 for(int i=1;i<=n;i++){
22 l=0;
23 for(int j=0;j<=m-1;j++){
24 if(s[i][j]=='.')l++;
25 else{
26 ans+=max(0,l-k+1);
27 l=0;
28 }
29 if(j==(m-1)&&s[i][j]!='*')
30 ans+=max(0,l-k+1);
31 }
32 }
33 for(int j=0;j<=m-1;j++){
34 l=0;
35 for(int i=1;i<=n;i++){
36 if(s[i][j]=='.') l++;
37 else{
38 ans+=max(0,l-k+1);
39 l=0;
40 }
41 if(i==n&&s[i][j]!='*')
42 ans+=max(0,l-k+1);
43 }
44 }
45 if(k==1) ans/=2;
46 cout<<ans<<endl;
47 }
48 }
Codeforces 919 C. Seat Arrangements的更多相关文章
- Codeforces Round #460 (Div. 2)-C. Seat Arrangements
C. Seat Arrangements time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- codeforces 919C Seat Arrangements 思维模拟
C. Seat Arrangements time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 919C - Seat Arrangements
传送门:http://codeforces.com/contest/919/problem/C 给出一张n×m的座位表(有已占座位和空座位),请选择同一行(或列)内连续的k个座位.求选择的方法数. H ...
- 【Codeforces Round #460 (Div. 2) C】 Seat Arrangements
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用pre[i][j]表示第i行前j列的和. 然后枚举连续座位的最左上点. (有两种可能向右或向下k个. 则还需要处理出pre2[i] ...
- Codeforces 919 E Congruence Equation
题目描述 Given an integer xx . Your task is to find out how many positive integers nn ( 1<=n<=x1&l ...
- Codeforces 919 D Substring
题目描述 You are given a graph with nn nodes and mm directed edges. One lowercase letter is assigned to ...
- Codeforces 919 B. Perfect Number
B. Perfect Number time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces 919 A. Supermarket
这场cf有点意思,hack场,C题等于1的特判hack很多人(我hack成功3个人,上分了,哈哈哈,咳咳...) D题好像是树形dp,E题好像是中国剩余定理,F题好像还是dp,具体的不清楚,最近dp的 ...
- Codeforces 919 行+列前缀和 树上记忆化搜索(树形DP)
A B C #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) ...
随机推荐
- 自动化运维工具——pssh
PSSH介绍 pssh是一个python编写可以在多台服务器上执行命令的工具,同时支持拷贝文件,是同类工具中很出色的.它的用法可以媲美ansible的一些简单用法,执行起来速度比ansible快它支持 ...
- 谷歌放弃“不作恶” Alphabet要“遵守法律互相尊重”
对于一些谷歌粉而言,谷歌那条“不作恶(Don’t be evil)”的行为准则是他们引以为傲的精神信仰.这一准则于1999年被首次确认,谷歌在2004年申请上市时也提到了这一点.不过现在这一点要改变了 ...
- 01 Django基础知识
相关概念 软件框架 一个公司是由公司中的各部部门来组成的,每一个部门拥有特定的职能,部门与部门之间通过相互的配合来完成让公司运转起来. 一个软件框架是由其中各个软件模块组成的,每一个模块都有特定的功能 ...
- Python9-进程池-day38
复习 # 信号量 from multiprocessing import Semaphore # 用锁的原理实现的,内置了一个计数器 # 在同一个事件,只能有指定数量的进程执行某一段被控制住的代码 # ...
- poj 2376 选择工作区间问题 贪心算法
题意:给一些工作区间,如何选取最小的工作数量,覆盖[1,T]的工作时长 一开始的思路,当然也是错误的思路: 我想着,最小工作数量是吧?那肯定就是选择结束时间最晚的,给结束时间来一个排序.哎这个思路错误 ...
- WPF触控程序开发(三)——类似IPhone相册的反弹效果
用过IPhone的都知道,IPhone相册里,当图片放大到一定程度后,手指一放,会自动缩回,移动图片超出边框后手指一放,图片也会自动缩回,整个过程非常和谐.自然.精确,那么WPF能否做到呢,答案是肯定 ...
- Java学习——面对对象的思想入门
本文是看过<head first Java>之后的一点感悟,写点东西帮忙以后回忆,Java目前在我的工作中用到还不多,而我又对面对对象的编程非常的感兴趣.曾经在MFC平台上写过 ...
- 【Jenskins】安装与配置
Jenskins教程:http://www.yiibai.com/jenkins/ 一.Jenskins的安装 1.jenskins下载和启动 Jenskins下载地址:https://jenkins ...
- JS实现——贪吃蛇
把以下代码保存成Snake.html文件,使用Google或360浏览器打开 <!DOCTYPE HTML> <html> <head> <meta char ...
- navicat for mysql 在win7下设置定时计划之导出数据处理
navicat for mysql 在win7下设置定时计划之导出数据处理 博客分类: mysql navitcatmysql定时任务导出 前两篇记录了,navicat for mysql计划的入门 ...