【Codeforces Round #460 (Div. 2) C】 Seat Arrangements
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
用pre[i][j]表示第i行前j列的和。
然后枚举连续座位的最左上点。
(有两种可能向右或向下k个。
则还需要处理出pre2[i][j]表示第j列前i行的和。
(都可以O(N^2)求出
然后pre[i][j+k-1]-pre[i][j-1]就是第i行第j列往右k个格子的空(或被占据)的格子数目了。
看看是不是符合要求就好。
往下扩展同理。
k==1的时候只要取向右一种就好。所以直接除个2
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3;
int n,m,k;
int a[N+10][N+10],pre[N+10][N+10];
char s[N+10][N+10];
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m >> k;
for (int i = 1;i <= n;i++){
cin >>(s[i]+1);
}
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
if (s[i][j]=='*')
a[i][j] = 1;
else
a[i][j] = 0;
for (int i = 1;i <= n;i++){
pre[i][0] = 0;
for (int j = 1;j <=m;j++)
pre[i][j] = pre[i][j-1]+a[i][j];
}
long long ans = 0;
for (int i = 1;i <=n;i++)
for (int j = 1;j <= m;j++){
int l = j+k-1;
if (l <= m){
int temp = pre[i][l]-pre[i][j-1];
if (temp==0){
ans++;
}
}
}
memset(pre,0,sizeof pre);
for (int j = 1;j <= m;j++){
pre[0][j] = 0;
for (int i = 1;i <= n;i++){
pre[i][j] = pre[i-1][j] + a[i][j];
}
}
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++){
int l = i + k-1;
if (l <= n){
int temp = pre[l][j]-pre[i-1][j];
if (temp==0){
ans++;
}
}
}
if (k==1) ans/=2;
cout<<ans<<endl;
return 0;
}
【Codeforces Round #460 (Div. 2) C】 Seat Arrangements的更多相关文章
- 【Codeforces Round #460 (Div. 2) D】Substring
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果有环 ->直接输出-1 (拓扑排序如果存在某个点没有入过队列,说明有环->即入队的节点个数不等于n 否则. 说明可以 ...
- 【Codeforces Round #460 (Div. 2) B】 Perfect Number
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 直接暴力求出第k个perfect数字就好. 纯模拟. [代码] #include <bits/stdc++.h> #de ...
- 【Codeforces Round #460 (Div. 2) A】 Supermarket
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 就是让你求m*(ai/bb)的最小值 [代码] #include <bits/stdc++.h> #define dou ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
随机推荐
- [JAVA · 0基础]:3.转义字符
定义 全部的ASCII码都能够用"\"加数字(通常是8进制数字)来表示.而C中定义了一些字母前加"\"来表示常见的那些不能显示的ASCII字符,如\0,\t,\ ...
- 数学之路-python计算实战(6)-numpy-ndarray
>>>> mya=np.zeros(shape=(2,2)) >>>> mya array([[ 0., 0.], [ 0., 0.]]) > ...
- Experience Design for Sexable Forum
Mars March 16, 2015
- 学习bootstrap
菜鸟教程 bootstrap开发框架 伍华聪 Bootstrap——一款超好用的前端框架
- 安卓开发--scrollview
package com.cnn.scrollviewdemo01; import android.R.integer; import android.annotation.SuppressLint; ...
- json数据字典,以及数据在下拉框中显示
建立person_vocation.json数据字典文件,内容: [ {"id":1,"disabled":false,"selected" ...
- Rain and Umbrellas(dp)
题目链接 http://codeforces.com/problemset/problem/988/F 令dp[i][j]为走到目标为i处,手里拿着第j把伞,同时注意,在某处可能存在不止一把伞 #in ...
- exsi主机之间使用scp拷贝文件超时问题
exsi主机之间使用scp拷贝文件直接连接不上报错超时: 解决: 防火墙勾选ssh选项
- iOS开发——导入c文件引起的 Unknown type name 'NSString' 错误
一般情况下出现“Unknown type name”是头文件互相引用出现的,这里不是这个,由于源码使用是c\c++与oc混编,下面三种可以解决问题方案. 解决方案一: 选择所有.c文件,将属性的 id ...
- caioj 1083 动态规划入门(非常规DP7:零件分组)(LIS)
这道题题目给的顺序不是固定的 所以一开始要自己排序,按照w来排序 后来只要看l就可以了 然后求最长下降子序列即可(根据那个神奇的定理,LIS模板里有提到) #include<cstdio> ...