2021牛客多校1 D Determine the Photo Position

131 篇文章 0 订阅

D Determine the Photo Position

链接:https://ac.nowcoder.com/acm/contest/11166/D
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

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.

输入描述:

The first line contains two integers n,m(2≤n,m≤2000)n,m(2 \le n,m \le 2000)n,m(2≤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. 

输出描述:

Output one integer in a line, indicating the answer.

示例1

输入

[复制](javascript:void(0)😉

5 3
00000
01110
01110
01110
00000
222

输出

[复制](javascript:void(0)😉

6

示例2

输入

[复制](javascript:void(0)😉

3 2
101
010
101
22

输出

[复制](javascript:void(0)😉

0

示例3

输入

[复制](javascript:void(0)😉

3 1
101
010
101
2

输出

[复制](javascript:void(0)😉

4

思路和代码

暴力,没什么可说的

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <limits.h>
#include <assert.h>
#include <functional>
#include <numeric>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb          push_back
#define ppb         pop_back
#define lbnd        lower_bound
#define ubnd        upper_bound
#define endl        '\n'
#define mll         map<ll,ll>
#define msl         map<string,ll>
#define mls         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x)  for(auto& a : x)
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define vll         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define DEBUG       cerr<<"/n>>>I'm Here<<</n"<<endl;
#define display(x)  trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;
#define ini(a)      memset(a,0,sizeof(a))
#define ini2(a,b)   memset(a,b,sizeof(a))
#define rep(i,a,b)  for(int i=a;i<=b;i++)
#define sc          ll T;cin>>T;for(ll Q=1;Q<=T;Q++)
#define lowbit(x)   x&(-x)
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DBG(x) \
    (void)(cout << "L" << __LINE__ \
    << ": " << #x << " = " << (x) << '\n')
#define TIE \
    cin.tie(0);cout.tie(0);\
    ios::sync_with_stdio(false);

//using namespace __gnu_pbds;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 2000;
const int N = 10001;

char fa[maxn];
char cb[maxn][maxn];
ll len;



ll fun(char *a){
	for(int i=0;i<len;i++){
		if(a[i]!='0')return 0;
	}
	return 1;
}

void solve(){
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>cb[i];
	}
	
	cin>>fa;
	len = strlen(fa);
	ll ans = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n-len+1;j++){
			if(fun(cb[i]+j)==1) ans++;
		}
	}
	cout<<ans<<endl;
}

int main()
{
//    #ifndef ONLINE_JUDGE
//    freopen ("input.txt","r",stdin);
//    #else
//    #endif
	solve();
//    sc{solve();}
//    sc{cout<<"Case "<<Q<<":"<<endl;solve();}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值