D-Determine the Photo Positio
2021/7/17 23:38:24
本文主要是介绍D-Determine the Photo Positio,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
题目描述
You have taken the graduation picture of graduates. The picture could be regarded as a matrix A of n×nn \times nn×n, each element in A is 0 or 1, representing a blank background or a student, respectively.
However, teachers are too busy to take photos with students and only took a group photo themselves. The photo could be regarded as a matrix B of 1×m1 \times m1×m where each element is 2 representing a teacher.
As a master of photoshop, your job is to put photo B into photo A with the following constraints:
- you are not allowed to split, rotate or scale the picture, but only translation.
- each element in matrix B should overlap with an element in A completely, and each teacher should overlap with a blank background, not shelter from a student.
Please calculate the possible ways that you can put photo B into photo A.
输入描述:
1 2 3 4 5 | The first line contains two integers n,m(1≤n,m≤2000)n,m(1 \le n,m \le 2000)n,m(1≤n,m≤2000) indicating the size of photos A and B. In the next $n$ lines,each line contains n{n}n characters of '0' or '1',representing the matrix A. The last line contains m{m}m characters of '2', representing matrix B. |
输出描述:
1 | Output one integer in a line, indicating the answer. |
示例1
输入
复制
1 2 3 4 5 6 7 | 5 3 00000 01110 01110 01110 00000 222 |
输出
复制
1 | 6 |
示例2
输入
复制
1 2 3 4 5 | 3 2 101 010 101 22 |
输出
复制
1 | 0 |
示例3
输入
复制
1 2 3 4 5 | 3 1 101 010 101 2 |
输出
复制
1 | 4 |
思路:将一整行放入矩阵A中,只能放在连续m个为0的区域,因此只能每行每行看,用x记录下连续0的个数,当x>=m时,ans++;当不为0时,x清0;
代码如下:
#include <bits/stdc++.h>
using namespace std;
int n,m,ans;
string s;
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>s; //因为不能旋转方向,所以只能每行每行研究
int x =0;//连续0的个数
for(int i=0;i<s.size();i++){
if(s[i]=='0'){
x++;
if(x>=m) ans++;
}
else x=0; //遇到不是0了,清零
}
}
cin>>s;//这个串没啥用,只需要知道个数m即可
cout<<ans<<endl;
return 0;
}
这篇关于D-Determine the Photo Positio的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-15我打造的超强PowerShell脚本开发环境是怎样的?
- 2025-01-15GitHub Actions工作目录详解
- 2025-01-15DoorDash的实时数据处理系统详解
- 2025-01-15Git高手秘籍:开发者终极速查表
- 2025-01-15使用Laravel和Neon构建多租户SaaS应用指南
- 2025-01-15给新手的9本最佳Linux书籍推荐
- 2025-01-15扩展外置模式以应对海量消息(每天处理2B+消息)
- 2025-01-15.NET技术为何越来越不受青睐了?
- 2025-01-15万字长文,k8s之父带你阅读 deployment 源码
- 2025-01-15k8s之父带你阅读 replicaset 源码【2w字】