码迷,mamicode.com
首页 > 其他好文 > 详细

解题:POI 2015 Piecz??

时间:2018-11-07 22:13:02      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:tar   没有   直接   open   分享图片   code   bool   hide   poi   

题面

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

以印章左上角的‘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

 

解题:POI 2015 Piecz??

标签:tar   没有   直接   open   分享图片   code   bool   hide   poi   

原文地址:https://www.cnblogs.com/ydnhaha/p/9925957.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!