Bzoj3750 [poi2015]pieczęć

模拟不水题

阅读全文大概需要 3分钟
本文总阅读量
Posted by yjjr's blog on November 26, 2018

标签:模拟

题目

题目传送门

Description

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

Input

第一行一个整数\(q(1\leq q\leq 10)\),表示测试点数量。 接下来q个测试点,每个测试点中: 第一行包含4个整数\(n,m,a,b(1\leq n,m,a,b\leq 1000)\)。 接下来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;
} 
本文可以转载,但必须附上原文链接,否则你会终生找不到妹子!!!欢迎关注我的CSDN: ahyjjr