[贪心] hdu5386 多校联合第八场 Cover

Cover

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1049    Accepted Submission(s): 217
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

我们只要每次找一行或一列颜色除了00都相同的,然后如果有对应的操作,就把这行这列都赋值成00即可

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
#include<cmath>
using namespace std;

int INF =0x3f3f3f3f;
int cur[105][105], goal[105][105];
bool vis[105][105];
int n, m;
struct nde
{
    char c;
    int x, y, id;
    int sortlist;
} node[555];

bool cmp(nde a, nde b)
{
    return a.sortlist<b.sortlist;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        INF = 0x3f3f3f3f;
        memset(node,0,sizeof node);
        memset(vis,0,sizeof vis);

        scanf("%d%d",&n,&m);
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
                scanf("%d",&cur[i][j]);

        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
                scanf("%d",&goal[i][j]);

        for(int i=0; i<m; i++)
        {
            char s[10];
            scanf("%s%d%d",s,&node[i].x,&node[i].y);
            node[i].c=s[0];
            node[i].id=i+1;
        }
        int temp = m;
        while(temp--)
        {
            for(int i=0; i<m; i++)
            {
                if(node[i].sortlist>0) continue;
                bool flag=true;
                if(node[i].c=='L')
                {
                    //如果修改过了该值或者该值就是原来的 那就不用再改了
                    for(int j=1; j<=n; j++)
                    if(!(goal[j][node[i].x] == node[i].y || vis[j][node[i].x]))
                        flag=false;
                    if(flag)
                    {
                        for(int j=1; j<=n; j++)
                            vis[j][node[i].x]=true; //访问过了
                        node[i].sortlist=temp;
                        break;
                    }
                }
                else if (node[i].c =='H')
                {
                    for(int j=1; j<=n; j++)
                    {
                    if(!(goal[node[i].x][j] == node[i].y || vis[node[i].x][j]))
                        flag=false;
                    }
                    if(flag)
                    {
                        for(int j=1; j<=n; j++)
                            vis[node[i].x][j]=true;
                        node[i].sortlist=temp;
                        break;
                    }
                }
            }
        }

        sort(node,node+m,cmp);

        int i = 0;
        for(i=0; i<m-1; i++)
            printf("%d ",node[i].id);
        printf("%d\n",node[i].id);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值