解题:POI 2015 Pieczęć

题面

发现好像没有什么好做法,那就模拟么=。=

以印章左上角的'x'为基准,记录印章上'x'的相对位置模拟。记录相对位置是因为可能有这种情况↓

直接模拟是会漏掉的=。=

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int N=1005,M=2005;
 6 int mapp[M][M],pos[N*N][2];
 7 int n,m,a,b,T,cnt,firx,firy;
 8 char rd[N];
 9 inline void i207M()
10 {
11     cnt=0,firx=firy=-1;
12     memset(mapp,0,sizeof mapp);
13 }
14 inline bool judge()
15 {
16     register int i,j;
17     for(i=1;i<=n;i++)
18         for(j=1;j<=m;j++)
19             if(mapp[i][j]) return false;
20     return true;
21 }
22 inline bool print(int x,int y)
23 {
24     register int i;
25     for(i=1;i<=cnt;i++)
26     {
27         int nx=x+pos[i][0],ny=y+pos[i][1];
28         if(!mapp[nx][ny]) return false;
29         if(nx>n||ny>m) return false;
30         mapp[nx][ny]=0;
31     }
32     return true;
33 }
34 int main ()
35 {
36     register int i,j;
37     scanf("%d",&T);
38     while(T--)
39     {
40         i207M();
41         scanf("%d%d%d%d",&n,&m,&a,&b);
42         for(i=1;i<=n;i++)
43         {
44             scanf("%s",rd+1);
45             for(j=1;j<=m;j++)
46                 mapp[i][j]=(rd[j]=='x');
47         }
48         for(i=1;i<=a;i++)
49         {
50             scanf("%s",rd+1);
51             for(j=1;j<=b;j++)
52                 if(rd[j]=='x')
53                 {
54                     if(firx==-1) firx=i,firy=j;
55                     pos[++cnt][0]=i-firx,pos[cnt][1]=j-firy;
56                 }
57         }
58         if(firx==-1&&!judge()) {printf("NIE\n"); continue;}
59         bool f=true; 
60         for(i=1;i<=n&&f;i++)
61             for(j=1;j<=m&&f;j++)
62                 if(mapp[i][j]&&!print(i,j)) f=false; 
63         (f&&judge())?printf("TAK\n"):printf("NIE\n");
64     }
65     return 0;
66 }
View Code

 

转载于:https://www.cnblogs.com/ydnhaha/p/9925957.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值