zoukankan      html  css  js  c++  java
  • 解题: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
    "); 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
    "):printf("NIE
    ");
    64     }
    65     return 0;
    66 }
    View Code
  • 相关阅读:
    Babelfish
    【动态规划】货币面值
    contest 1.18
    contest 1.17
    contest 1.16
    contest 1.15
    contest 1.14
    contest 1.13
    contest 12.31
    [cf]Round #529 (Div. 3)
  • 原文地址:https://www.cnblogs.com/ydnhaha/p/9925957.html
Copyright © 2011-2022 走看看