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 n∗n 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



1≤color[i][j]≤n

T=5

1≤n≤100

1≤m≤500
 
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\n",ans[m]);
}
return 0;
}

HDU 5386 Cover(模拟)的更多相关文章

  1. hdu 5386 Cover (暴力)

    hdu 5386 Cover Description You have an matrix.Every grid has a color.Now there are two types of oper ...

  2. HDU 5386 Cover

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5386 题目大意:给一个初始矩阵(n×n).一个目标矩阵(n×n)和m个操作,要求找到一种操作顺序,使初 ...

  3. HDU 6311 Cover (无向图最小路径覆盖)

    HDU 6311 Cover (无向图最小路径覆盖) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...

  4. 暴力/思维 HDOJ 5386 Cover

    题目传送门 /* 题意:给出刷墙的所有的方法,求一种顺序,使得原矩阵刷成目标矩阵 暴力:(题解)我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可 */ /* ...

  5. hdoj 5386 Cover

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5386 倒着推的一个挺暴力的题,看着和数学有关系,然而并没有, 不要一看到含有数学元素就考虑这是一个数学 ...

  6. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

  7. hdu 5071 Chat(模拟)

    题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...

  8. hdu 4740【模拟+深搜】.cpp

    题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...

  9. HDU 2568[前进]模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...

随机推荐

  1. (二)React简介

    React简介 2-1: React v16 (React Fiber) React比Vue更灵活 Vue更简单 2-2 开发环境搭建 如何开始:(两种方式) 1.传统方式script标签引入.js文 ...

  2. POJ-2253 Frogger dijsktra查找间隔最小的路径

    题目链接:https://cn.vjudge.net/problem/POJ-2253 题意 一只Forg需要从节点1走到节点n 现要找一条各个间隔最小的路径 问间隔最小是多少 思路 用dijsktr ...

  3. ajaxFileUpload 返回的数据报错

    $.ajaxFileUpload({ url : '/updateMallGoods', data : { "goodsName":goodsName, "proDesc ...

  4. Python3+Gurobi使用教程(一)

    Gurobi使用教程 1.Gurobi使用的一般框架 from gurobipy import * try: m=Model('modelname') except GurobiError: prin ...

  5. C语言回调

    来源:https://www.cnblogs.com/jiangzhaowei/p/9129105.html 1. 什么是回调函数? 回调函数,光听名字就比普通函数要高大上一些,那到底什么是回调函数呢 ...

  6. Failed to initialize component [Connector[HTTP/1.1-8086]]

    严重: Failed to initialize end point associated with ProtocolHandler ["http-apr-8086"] java. ...

  7. [MST] Restore the Model Tree State using Hot Module Reloading when Model Definitions Change

    n this lesson, we will set up Hot Module Reloading(HMR), making it possible to load new definitions ...

  8. django 笔记12 session

    第一步写好函数,然后生成数据库session表 python manage.py makemigrations python manage.py migrate session原理: .Session ...

  9. User-defined types

    We have used many of Python’s built-in types; now we are going to define a new type. As an example, ...

  10. PostgreSQL Replication之第六章 监控您的设置(2)

    6.2 检查pg_stat_replication 检查归档以及 archive_command主要用于即时恢复( PITR,Point-In-Time- Recovery).如果您想监控一个基于流的 ...