2015 多校联赛 ——HDU5386(暴力)

来源:互联网 发布:全知之眼纹身意义 编辑:程序博客网 时间:2024/06/05 03:59

Sample Input
13 52 2 1 2 3 3 2 1 3 3 3 3 3 3 3 3 3 3 H 2 3L 2 2H 3 3H 1 3L 2 3
 

Sample Output
5 2 4 3 1


给你一个初始矩阵和目标矩阵,包含‘L’ , ' H' 两个操作, ‘L x y’  表示把第x列全赋值成y, ‘Hx y’  表示把第x行全赋值成y。

求怎样的顺序可以得出目标矩阵。

倒着求解,在目标矩阵上你肯定能找到最后一个操作,这样倒推出答案即可


#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#include<vector>#include<map>#include<set>#include<queue>#include<stack>#include<string>#include<algorithm>using namespace std;#define maxn 200050int T,n,m,t,k,l,tot,j;int a[105][105];int b[505],c[505],ans[505];char p[505],ch;int main(){    scanf("%d",&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]);        t = 0;        tot = 0;        for(int i = 1; i <= m; i++)        {            for(ch=getchar(); ch!='H'&&ch!='L'; ch=getchar());            p[i] = ch;            scanf("%d%d",&b[i],&c[i]);        }        while(tot < m)        {            for(int i=1;i<=m;++i)            if(b[i])            {                int t = b[i];                if(p[i] == 'L')                {                    for(j = 1; j <= n; j++)                        if(a[j][t] && a[j][t] != c[i])                            break;                    if(j > n)                    {                        for(int j = 1; j <= n; j++)                            a[j][t] = 0;                        b[i] = 0;                        ans[tot++] = i;                    }                }                else                {                    for(j = 1; j <= n; j++)                        if(a[t][j] && a[t][j] != c[i])                            break;                    if(j > n)                    {                        for(int j = 1; j <= n; j++)                            a[t][j] = 0;                        b[i] = 0;                        ans[tot++] = i;                    }                }            }        }        for(int i=m-1; i>=0; --i)printf("%d ",ans[i]);        printf("\n");    }    return 0;}










0 0
原创粉丝点击