zoukankan      html  css  js  c++  java
  • 【JZOJ4761】【NOIP2016提高A组模拟9.7】鼎纹

    题目描述

    题目描述

    输入

    输入

    输出

    输出

    样例输入

    2
    3 4 4 2
    1100
    0110
    1100
    10
    01
    10
    00
    2 2 2 2
    11
    11
    01
    10

    样例输出

    YES
    NO

    数据范围

    数据范围

    解法

    由于鼎纹中的第一个1必须被铜模中的第一个1覆盖,那么就用铜模覆盖掉鼎纹的第一个1,相应地继续枚举,每枚举到一个1就覆盖一次。

    代码

    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    const char* fin="aP1.in";
    const char* fout="aP1.out";
    const int inf=0x7fffffff;
    const int maxn=2007;
    int read(){
        char ch=getchar();
        int x=0;
        while (ch<'0' || ch>'9') ch=getchar();
        while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
        return x;
    }
    int t,t1,n1,m1,n2,m2,i,j,k,l,sx[2],sy[2],tx[2],ty[2],tmp,tmd;
    char a[maxn][maxn];
    char b[maxn][maxn];
    int c[maxn*maxn][2],tot;
    int az[maxn],bz[maxn][maxn],id;
    int main(){
        scanf("%d",&t);
        for (t1=1;t1<=t;t1++){
            scanf("%d%d%d%d
    ",&n1,&m1,&n2,&m2);
            sx[0]=sx[1]=inf;
            tx[0]=tx[1]=0;
            //----------------------------------------------------------
            id++;
            for (i=1;i<=n1;i++) {
                scanf("%s",a[i]+1);
                for (j=1;j<=m1;j++){
                    if (a[i][j]=='1'){
                        sx[0]=min(sx[0],j);
                        tx[0]=max(tx[0],j);
                        az[i]=id;
                    }
                }
                scanf("
    ");
            }
            for (i=1;i<=n1;i++) if (az[i]==id) {sy[0]=i;break;}
            for (i=n1;i;i--) if (az[i]==id) {ty[0]=i;break;}
            //----------------------------------------------------------
            id++;tot=0;
            for (i=1;i<=n2;i++) {
                scanf("%s",b[i]+1);
                for (j=1;j<=m2;j++){
                    if (b[i][j]=='1'){
                        c[++tot][0]=i;
                        c[tot][1]=j;
                        if (tot==1) tmp=c[1][0],tmd=c[1][1];
                        c[tot][0]-=tmp;
                        c[tot][1]-=tmd;
                        sx[1]=min(sx[1],j);
                        tx[1]=max(tx[1],j);
                        az[i]=id;
                    }
                }
                scanf("
    ");
            }
            for (i=1;i<=n2;i++) if (az[i]==id) {sy[1]=i;break;}
            for (i=n2;i;i--) if (az[i]==id) {ty[1]=i;break;}
            if (sx[0]==inf) {
                printf("YES
    ");
                continue;
            }
            if (sx[1]==inf) {
                printf("NO
    ");
                continue;
            }
            //----------------------------------------------------------
            //printf("%d %d %d %d %d %d %d %d
    ",sx[0],sy[0],tx[0],ty[0],sx[1],sy[1],tx[1],ty[1]);
            bool no=false;
            for (i=sy[0];i<=ty[0];i++){
                for (j=sx[0];j<=tx[0];j++){
                    if (bz[i][j]<t1 && a[i][j]=='1'){
                        for (k=1;k<=tot;k++){
                            tmp=i+c[k][0];
                            tmd=j+c[k][1];
                            if (tmp<=ty[0] && tmd<=tx[0] && bz[tmp][tmd]<t1 && a[tmp][tmd]=='1') bz[tmp][tmd]=t1;
                            else{
                                printf("NO
    ");
                                no=true;
                                break;
                            }
                        }
                    }
                    if (no) break;
                }
                if (no) break;
            }
            if (!no) printf("YES
    ");
        }
        return 0;
    }
  • 相关阅读:
    Javascript错误调试与处理
    大话数据结构笔记——第七章 图
    大话数据结构笔记——第六章 树
    前端常见面试题(三)垂直居中的10种方式
    优化transform在过渡效果中出现文字模糊和抖动问题
    H-ui 管理系统
    thinkphp第一节结构
    php实现验证码
    fullpage.js
    jquery的使用
  • 原文地址:https://www.cnblogs.com/hiweibolu/p/6714904.html
Copyright © 2011-2022 走看看