1.26
https://ac.nowcoder.com/acm/problem/53676
秘法土震
二维前缀和的题目,
和此题配合食用效果更佳
子矩阵的和 https://www.acwing.com/problem/content/798/
秘法土震code:
#include<iostream> using namespace std; int n,m,k,s[1010][1010],ans; char ch; int main() { cin>>n>>m>>k; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { cin>>ch; s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+ch-48; } for(int i=k;i<=n;i++) for(int j=k;j<=m;j++) {// 画图格点化可以促进理解,原点是0,0,末是n,m if(s[i][j]-s[i-k][j]-s[i][j-k]+s[i-k][j-k]>0) ans++; } cout<<ans; }