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;
    }
    


  • 相关阅读:
    值得 Web 开发人员学习的20个 jQuery 实例教程
    15款优雅的 WordPress 电子商务网站主题
    Red Pen
    经典网页设计:无缝过渡的响应式设计案例
    值得 Web 开发人员收藏的20个 HTML5 实例教程
    mysql分库 分表
    MySQL大数据量快速分页实现
    mysql全局唯一ID生成方案(二)
    使用 SendARP 获取 MAC 地址(使用SendARP API函数,很多相关文章)
    锁是用来解决并发问题
  • 原文地址:https://www.cnblogs.com/mthoutai/p/7040564.html
Copyright © 2011-2022 走看看