HDU 5386 Cover

Cover


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
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
 
想复杂了,暴力解决即可,原始数组没有,从目标数组倒着思考每一个操作,多次重复,排序即可。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define inf 0x7fffffff
#define maxn 100010
using namespace std;
struct OP
{
        char s;
        int c, v;
}op[550];
int a[110][110];
int b[110][110];
int vis[550], ran[550];
int main()
{
        int t;
        scanf("%d", &t);
        while (t--)
        {
                int n, m;
                scanf("%d %d", &n, &m);

                for (int i = 0; i < n; i++)
                {
                        for (int j = 0; j < n; j++)
                        {
                                scanf("%d", &a[i][j]);
                        }
                }
                for (int i = 0; i < n; i++)
                {
                        for (int j = 0; j < n; j++)
                        {
                                scanf("%d", &b[i][j]);
                        }
                }
                memset(vis, 0, sizeof(vis));
                for (int i = 0; i < m; i++)
                {
                        scanf(" %c %d %d", &op[i].s, &op[i].c, &op[i].v);
                }
                int cnt = 1;
                while (cnt <= m)
                {
                        for (int i = 0; i < m; i++)
                        {
                                if (vis[i])
                                {
                                        continue;
                                }
                                if (op[i].s == 'H')
                                {
                                        int flag = 0;
                                        int pos = op[i].c-1;
                                        for (int j = 0; j < n; j++)
                                        {
                                                if (b[pos][j] != 0 && b[pos][j] != op[i].v)
                                                {
                                                        flag = 1;
                                                        break;
                                                }
                                        }
                                        if (flag == 0)
                                        {
                                                vis[i] = 1;
                                                ran[cnt++] = i;
                                                for (int j = 0; j < n; j++)
                                                {
                                                        b[pos][j] = 0;
                                                }
                                        }
                                }
                                else
                                {
                                        int flag = 0;
                                        int pos = op[i].c-1;
                                        for (int j = 0; j < n; j++)
                                        {
                                                if (b[j][pos] != 0 && b[j][pos] != op[i].v)
                                                {
                                                        flag = 1;
                                                        break;
                                                }
                                        }
                                        if (flag == 0)
                                        {
                                                vis[i] = 1;
                                                ran[cnt++] = i;
                                                for (int j = 0; j < n; j++)
                                                {
                                                        b[j][pos] = 0;
                                                }
                                        }
                                }
                        }
                }
                for (int i = m; i >= 1; i--)
                {
                        if (i != 1)
                        {
                                printf("%d ", ran[i] + 1);
                        }
                        else
                        {
                                printf("%d\n", ran[i] + 1);
                        }
                }
        }
        return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值