hdu 5386 Cover 暴力模拟

题意:两种操作:

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;

给出初始矩阵和目标矩阵,给出m种操作,将其排个序,使得初始矩阵经过排序后的操作能够变成目标矩阵。

从目标矩阵直接反着模拟回来就行了,而且题目保证有解

//#include <bits/stdc++.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <time.h>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
///cout << fixed << setprecision(13) << (double) x << endl;
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
#define ls rt << 1
#define rs rt << 1 | 1
#define pi acos(-1.0)
#define eps 1e-8
#define Mp(a, b) make_pair(a, b)
#define asd puts("asdasdasdasdasdf");
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef pair <int, int> pl;
//typedef __int64 LL;
const int inf = 0x3f3f3f3f;
const int N = 550;

struct node{
    int x, y, op;
}a[N];
int n, m;
int b[N][N], c[N][N];
vector <int> v;
int vis[N];

int main()
{
    int tot;
    scanf("%d", &tot);
    while( tot-- ) {
        scanf("%d%d", &n, &m);
        v.clear();
        memset( vis, 0, sizeof( vis ) );
        for( int i = 1; i <= n; ++i ) {
            for( int j = 1; j <= n; ++j )
                scanf("%d", &b[i][j]);
        }
        for( int i = 1; i <= n; ++i ) {
            for( int j = 1; j <= n; ++j )
                scanf("%d", &c[i][j]);
        }
        for( int i = 1; i <= m; ++i ) {
            char op[10];
            int x, y;
            scanf("%s%d%d", op, &x, &y);
            if( op[0] == 'H' )
                a[i].op = 1;
            else
                a[i].op = 0;
            a[i].x = x, a[i].y = y;
        }
        int cnt = 0;
        while( cnt < m ) {
            for( int i = 1; i <= m; ++i ) {
                if( vis[i] )
                    continue;
                int op = a[i].op, x = a[i].x, y = a[i].y;
                if( op == 1 ) {
                    bool OK = 1;
                    for( int j = 1; j <= n; ++j ) {
                        if( c[x][j] != y && c[x][j] != -1 ) {
                            OK = 0;
                            break;
                        }
                    }
                    if( OK ) {
                        vis[i] = 1;
                        for( int j = 1; j <= n; ++j )
                            c[x][j] = -1;
                        v.push_back( i );
                        cnt++;
                    }
                }
                else {
                    bool OK = 1;
                    for( int j = 1; j <= n; ++j ) {
                        if( c[j][x] != -1 && c[j][x] != y ) {
                            OK = 0;
                            break;
                        }
                    }
                    if( OK ) {
                        vis[i] = 1;
                        for( int j = 1; j <= n; ++j )
                            c[j][x] = -1;
                        v.push_back( i );
                        cnt++;
                    }
                }
            }
        }
        for( int i = m-1; i >= 0; -- i )
            printf("%d%c", v[i], i == 0? '\n': ' ');
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值