zoukankan      html  css  js  c++  java
  • HDU 5386 Cover(模拟)

    Cover

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 966    Accepted Submission(s): 320
    Special Judge


    Problem Description
    You have an nn matrix.Every grid has a color.Now there are two types of operating:
    L x y: for(int i=1;i<=n;i++)color[i][x]=y;
    H x y:for(int i=1;i<=n;i++)color[x][i]=y;
    Now give you the initial matrix and the goal matrix.There are m operatings.Put in order to arrange operatings,so that the initial matrix will be the goal matrix after doing these operatings

    It's guaranteed that there exists solution.
     

    Input
    There are multiple test cases,first line has an integer T
    For each case:
    First line has two integer n,m
    Then n lines,every line has n integers,describe the initial matrix
    Then n lines,every line has n integers,describe the goal matrix
    Then m lines,every line describe an operating

    1color[i][j]n
    T=5
    1n100
    1m500
     

    Output
    For each case,print a line include m integers.The i-th integer x show that the rank of x-th operating is i
     

    Sample Input
    1 3 5 2 2 1 2 3 3 2 1 3 3 3 3 3 3 3 3 3 3 H 2 3 L 2 2 H 3 3 H 1 3 L 2 3
     

    Sample Output
    5 2 4 3 1
     

    Author
    SXYZ
     

    Source
     

    题意:给出两个n*n的矩阵。一个作为初始矩阵,一个作为目标矩阵。给出m个操作,操作有两种,

             一种是“L。x。y”,代表我们要把x这一行赋成y,还有一种是“H,x,y”,代表要把x这一列赋成y,

              问我们怎样安排这些操作才干把初始矩阵转化成目标矩阵。

    输出方案,special judge

    题解:最后一个操作肯定是把某一行或者某一列变成x,我们倒过来模拟,每次把最后一个操作找出来。即每次找到某一行

               或者某一列不为0的数都同样的,再找符合操作的。


    #include<cstring>
    #include<algorithm>
    #include<cstdio>
    #include<cmath>
    #include<iostream>
    #define N 110
    
    using namespace std;
    int a[N][N];
    
    struct Cao {
        char s[2];
        int x,v;
        bool used;
    } b[N*5];
    int ans[N*5];
    int n,m;
    
    bool is_H(int i,int k) {
        int x=-1;
        int j=1;
        for(; j<=n; j++) {
            if(a[i][j]) {
                x=a[i][j];
                break;
            }
        }
        if(x==-1)return true;
        if(x!=k)return false;
        for(; j<=n; j++) {
            if(a[i][j]&&a[i][j]!=x)return false;
        }
        return true;
    }
    
    bool is_L(int i,int k) {
        int x=-1;
        int j=1;
        for(; j<=n; j++) {
            if(a[j][i]) {
                x=a[j][i];
                break;
            }
        }
        if(x==-1)return true;
        if(x!=k)return false;
        for(; j<=n; j++) {
            if(a[j][i]&&a[j][i]!=x)return false;
        }
        return true;
    }
    
    int main() {
        // freopen("test.in","r",stdin);
        int t;
        cin>>t;
        while(t--) {
            scanf("%d%d",&n,&m);
            for(int i=1; i<=n; i++)
                for(int j=1; j<=n; j++)
                    scanf("%d",&a[i][j]);
            for(int i=1; i<=n; i++)
                for(int j=1; j<=n; j++)
                    scanf("%d",&a[i][j]);
            for(int i=1; i<=m; i++) {
                scanf("%s%d%d",b[i].s,&b[i].x,&b[i].v);
                b[i].used=0;
            }
            for(int h=m; h>=1; h--) {
                for(int i=1; i<=m; i++) {
                    if(b[i].used)continue;
                    if(b[i].s[0]=='H'&&is_H(b[i].x,b[i].v)) {
                        ans[h]=i;
                        b[i].used=1;
                        int p=b[i].x;
                        for(int k=1; k<=n; k++)
                            a[p][k]=0;
                        break;
                    } else if(b[i].s[0]=='L'&&is_L(b[i].x,b[i].v)) {
                        ans[h]=i;
                        b[i].used=1;
                        int p=b[i].x;
                        for(int k=1; k<=n; k++)
                            a[k][p]=0;
                        break;
                    }
                }
            }
            for(int i=1; i<m; i++)
                printf("%d ",ans[i]);
            printf("%d
    ",ans[m]);
        }
        return 0;
    }
    


  • 相关阅读:
    python chr函数
    WebStorm新建JS文件、CSS文件时自动生成文件注释
    Electron – 基础学习(2): 项目打包成exe桌面应用 之electron-packager
    Electron – 基础学习(1): 环境安装、创建项目及入门
    Electron – 项目报错整理【打包1】: WARNING: Make sure that .NET Framework 4.5 or later and Powershell 3 or later are installed, otherwise extracting the Electron zip file will hang.
    Vue – 基础学习(5):动态加载和注册组件
    Vue – 基础学习(4):事件修饰符
    Vue – 基础学习(3):$forceUpdate()和$nextTick()的区别
    Vue – 基础学习(2):组件间 通信及参数传递
    PHP_MySQL之间的连接步骤
  • 原文地址:https://www.cnblogs.com/mthoutai/p/7040564.html
Copyright © 2011-2022 走看看