zoukankan      html  css  js  c++  java
  • Determine the Photo Position —— 1D

    Determine the Photo Position

    题目描述

    给定一个\(n\times n\)的01矩阵\(A\),再给定一个\(1 \times m\)的矩阵\(B\),把\(B\)贴到\(A\)中连续的1上,问有几种贴法。

    范围

    \(n,m \leq 2000\)

    题解

    模拟

    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 2010;
    
    char mp[N][N];
    char t[N];
    int cl[N][N];
    int s[N][N];
    bool ok (int l,int r,char *p) {
    	for(int i = l;i <= r; ++i) {
    		if(p[i] != 0) return 0;
    	}
    	return 1;
    }
    
    int main () {
    	int n,m;
    	cin >> n >> m;
    	if(m > n) {
    		puts("0");
    	}
    	else {
    		int ans = 0;
    		for(int i = 1;i <= n; ++i) scanf("%s",mp[i] + 1);scanf("%s",t + 1);
    		for(int i = 1;i <= n; ++i) {
    			for(int j = 1;j <= n; ++j) {
    				cl[i][j] = mp[i][j] - '0';
    			}
    		}
    		for(int i = 1;i <= n; ++i) {
    			s[i][1] = cl[i][1];
    			for(int j = 2;j <= n; ++j) {
    				s[i][j] += s[i][j - 1] + cl[i][j];
    			}
    		}
    		for(int i = 1;i <= n; ++i) {
    			for(int j = 1;j <= n; ++j) {
    				if(cl[i][j] == 0) {
    					if(j + m - 1 <= n) {
    						int tmp = s[i][j + m - 1] - s[i][j - 1];
    						if(!tmp) {
    							//cout << i << ' ' << j << endl;
    							ans ++;
    						}
    					}
    				}
    			}
    		}
    		cout << ans << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    网站性能优化分类总结
    关于高度塌陷问题解决方法
    语义化HTML
    CSS命名规范
    linux开机过程
    Linux--sed命令
    博客声明
    linux-- grep命令
    pyinstaller使用-python项目转换成exe可执行文件
    python导出开发环境
  • 原文地址:https://www.cnblogs.com/akoasm/p/15132157.html
Copyright © 2011-2022 走看看