【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

用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的更多相关文章

  1. 【Codeforces Round #460 (Div. 2) D】Substring

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果有环 ->直接输出-1 (拓扑排序如果存在某个点没有入过队列,说明有环->即入队的节点个数不等于n 否则. 说明可以 ...

  2. 【Codeforces Round #460 (Div. 2) B】 Perfect Number

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 直接暴力求出第k个perfect数字就好. 纯模拟. [代码] #include <bits/stdc++.h> #de ...

  3. 【Codeforces Round #460 (Div. 2) A】 Supermarket

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 就是让你求m*(ai/bb)的最小值 [代码] #include <bits/stdc++.h> #define dou ...

  4. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  5. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  6. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  7. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  8. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  9. 【Codeforces Round #423 (Div. 2) B】Black Square

    [Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...

随机推荐

  1. 解决The hierarchy of the type is inconsistent错误

    可能的原因:自己的类继承于某个类,这个类或者这个类继承的类或者再往上继承的某个类所在的jar包没有被引入. 比如:使用Spring的AOP时,假设须要继承MethodBeforeAdvice和Afte ...

  2. Springmvc JSON交互

    先上前端javascript.ajax代码 <pre name="code" class="javascript"> function testAj ...

  3. ACM:动态规划,01背包问题

    题目: 有n件物品和一个容量为C的背包.(每种物品均仅仅有一件)第i件物品的体积是v[i],重量是w[i].选一些物品装到这个背包中,使得背包内物品在整体积不超过C的前提下重量尽量大. 解法:两种思路 ...

  4. 编写SDR SDRAM页突发模式控制器的注意点-下篇

    本来是没打算写这些的,但是后面逐渐发现点问题,所以决定再写一个下篇来补充说明一下. 图一 细心的网友会发现上篇末尾的打印是有点问题的,因为我的数据产生器产生的是1-200,1-200,1-200,1- ...

  5. POJ1180 Batch Scheduling 解题报告(斜率优化)

    题目链接:http://poj.org/problem?id=1180 题目描述: There is a sequence of N jobs to be processed on one machi ...

  6. Django和Flask相对总结目录

    Django中文文档官网:https://yiyibooks.cn/xx/Django_1.11.6/index.html Flask中文文档官网:https://dormousehole.readt ...

  7. ASP.NET 部分视图

    ASP.NET MVC 里的部分视图,相当于 Web Form 里的 User Control.我们的页面往往会有许多重用的地方,可以进行封装重用. 使用部分视图有以下优点:   1. 可以简写代码. ...

  8. appium使用教程(三)-------------用例编写

    1. 驱动 import os, time, unittest from appium import webdriver PATH = lambda p:os.path.abspath(os.path ...

  9. NodeJS学习笔记 进阶 (13)Nodejs进阶:5分钟入门非对称加密用法

    个人总结:读完这篇文章需要5分钟,这篇文章讲解了Node.js非对称加密算法的实现. 摘录自网络 地址: https://github.com/chyingp/nodejs-learning-guid ...

  10. iOS——集成支付宝 系统繁忙,请稍后再试ALI10

    问题描述:调用支付宝时,显示系统繁忙,请稍后再试(ALI10).代码没有报错,其他也是按照文档来的,为何老是提示显示系统繁忙? 解决方案:还需要在targets的中info里面,添加  url typ ...