BZOJ3750 [POI2015]Pieczęć

187 篇文章 0 订阅
40 篇文章 0 订阅

标签:模拟

题目

题目传送门

Description

一张 n × m n\times m n×m的方格纸,有些格子需要印成黑色,剩下的格子需要保留白色。你有一个 a × b a\times b a×b的印章,有些格子是凸起(会沾上墨水)的。你需要判断能否用这个印章印出纸上的图案。印的过程中需要满足以下要求:
(1)印章不可以旋转。
(2)不能把墨水印到纸外面。
(3)纸上的同一个格子不可以印多次。

Input

第一行一个整数 q ( 1 ≤ q ≤ 10 ) q(1\leq q\leq 10) q(1q10),表示测试点数量。
接下来q个测试点,每个测试点中:
第一行包含4个整数 n , m , a , b ( 1 ≤ n , m , a , b ≤ 1000 ) n,m,a,b(1\leq n,m,a,b\leq 1000) n,m,a,b(1n,m,a,b1000)
接下来n行,每行m个字符,描述纸上的图案。’.'表示留白,‘x’表示需要染黑。接下来a行,每行b个字符,描述印章。’.'表示不沾墨水,'x’表示沾墨水。

Output

对于每个测试点,输出TAK(是)或NIE(否)。

Sample Input

2
3 4 4 2
xx..
.xx.
xx..
x.
.x
x.
..
2 2 2 2
xx
xx
.x
x.

Sample Output

TAK
NIE

分析

枚举每个’x’,遇到就尝试用每个印章去盖,如果盖不上或者超出地图范围就返回

code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
	ll f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
//******head by yjjr******
const int maxn=1e3+6;
struct node{int x,y;}s[maxn*maxn];
int n,m,a,b,cnt=0,T;bool flag;
char st[maxn][maxn],ch;
void check(int x,int y){
	if(cnt==0)flag=0;
	rep(i,1,cnt){
		if(!flag)return;
		int dx=x+s[i].x,dy=y+s[i].y;
		if(dx<1||dx>n||dy<1||dy>m||st[dx][dy]=='.')flag=0;else st[dx][dy]='.';
	}
}
inline bool JUD(){
	n=read(),m=read(),a=read(),b=read();
	rep(i,1,n)scanf("%s",st[i]+1);
	rep(i,0,a-1)rep(j,0,b-1){cin>>ch;if(ch=='x')s[++cnt]=(node){i,j};}
	dep(i,cnt,1)s[i].x-=s[1].x,s[i].y-=s[1].y;
	flag=1;
	rep(i,1,n)rep(j,1,m)if(st[i][j]=='x')check(i,j);
	return flag;
}
int main(){
	T=read();
	while(T--){cnt=0;if(JUD())puts("TAK");else puts("NIE");}
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值