• bzoj3750 [POI2015]Pieczęć


    Description

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

    Input

    第一行一个整数q(1<=q<=10),表示测试点数量。
    接下来q个测试点,每个测试点中:
    第一行包含4个整数n,m,a,b(1<=n,m,a,b<=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
     
    贪心:对于当前某一个状态,一定要用印章的左上角来和最左上的那个点匹配
    然后变模拟了
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #define LL long long
    using namespace std;
    inline LL read()
    {
        LL x=0,f=1;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;
    }
    int T,n,m,a,b,cnt;
    bool map[1010][1010];
    bool mrk[1010][1010];
    int colx[1000010],coly[1000010];
    inline bool paint(int x,int y)
    {
        for (int i=1;i<=cnt;i++)
        {
            int nx=x+colx[i],ny=y+coly[i];
            if (nx<1||ny<1||nx>n||ny>m||!mrk[nx][ny])return 1;
            mrk[nx][ny]=0;
        }
        return 0;
    }
    inline void work()
    {
        n=read();m=read();
        a=read();b=read();
        for(int i=1;i<=n;i++)
            for (int j=1;j<=m;j++)
            {
                char ch=getchar();while (ch!='x'&&ch!='.')ch=getchar();
                mrk[i][j]=map[i][j]=(ch=='x');
            }
        cnt=0;
        for (int i=1;i<=a;i++)
            for (int j=1;j<=b;j++)
            {
                char ch=getchar();while (ch!='x'&&ch!='.')ch=getchar();
                if (ch=='x')
                {
                    colx[++cnt]=i;
                    coly[cnt]=j;
                }
            }
        if (cnt==0)
        {
            printf("NIE
    ");
            return;
        }
        int rex=colx[1],rey=coly[1];
        for (int i=1;i<=cnt;i++)
        {
            colx[i]-=rex;
            coly[i]-=rey;
        }
        for(int i=1;i<=n;i++)
            for (int j=1;j<=m;j++)
                if (mrk[i][j])
                {
                    if (paint(i,j))
                    {
                        printf("NIE
    ");
                        return;
                    }
                }
        printf("TAK
    ");
    }
    int main()
    {
        T=read();
        while (T--)work();
    }
    
    ——by zhber,转载请注明来源
  • 相关阅读:
    Jenkins构建.NetFramework项目
    【转】linux docker 中实现某些程序段开机自启动
    SQL SERVER之查询 未创建索引的外键 和 所有外键及索引
    进入蓝牙协议开发领域外加ELink电子标签开发
    WPF DevExpress中GridControl动态修改行背景颜色 借用的
    新中新身份证阅读器 无法加载 DLL“SynIDCardAPI.dll”: 找不到指定的程序。 (异常来自 HRESULT:0x8007007F)。
    VS项目删除Git、不想用Git、
    Android 生成二维码
    [WPF 学习] 20. 增量更新续——用阿里云对象存储OSS
    RabbitMQ安装
  • 原文地址:https://www.cnblogs.com/zhber/p/4179514.html
Copyright © 2020-2023  润新知