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. anaconda安装basemap

    https://blog.csdn.net/m0_37556124/article/details/80560384 basemap安装前需要先安装geos conda install geos 其次 ...

  2. dede内链怎么优化,Dedecms内部链接优化技巧

    dede内链怎么优化,dedecms内部链接优化技巧 使用dedecms的过程中发现,可以通过dedecms的文档关键词维护功能.发表文章时候的关键词添加功能(也可以自动获取)以及核心设置里面的是否使 ...

  3. caioj 1161 欧拉函数3:可见点数

    (x, y)被看到仅当x与y互质 由此联想到欧拉函数 x=y是1个点,然后把正方形分成两半,一边是φ(n) 所以答案是2*∑φ(n)+1 #include<cstdio> #include ...

  4. Android图片旋转,缩放,位移,倾斜,对称完整演示样例(一)——imageView.setImageMatrix(matrix)和Matrix

    MainActivity例如以下: import android.os.Bundle; import android.view.MotionEvent; import android.view.Vie ...

  5. Android 手机影音 开发过程记录(六)

    前一篇已经将音乐播放及切换的相关逻辑弄好了,今天主要理一下剩余的部分,包含: 1. 自己定义通知栏的布局及逻辑处理 2. 滚动歌词的绘制 3. 歌词解析 效果图 通知栏 自己定义布局: <?xm ...

  6. HDU 2222 Keywords Search(AC自己主动机模板题)

    题意:给出一个字符串和若干个模板,求出在文本串中出现的模板个数. 思路:由于有可能有反复的模板,trie树权值记录每一个模板出现的次数就可以. #include<cstdio> #incl ...

  7. 用java实现螺旋数组

    接收数组的行数和列数,返回正序和倒序的螺旋数组 package cn.baokx; public class Test { public static void main(String[] args) ...

  8. less13 颜色值函数

    //通过十进制红色,绿色,蓝色三种值 (RGB) 创建不透明的颜色对象. div{ background: rgb(255,0,0); background: rgb(100%,0%,0%); } / ...

  9. 2.mongoDB 介绍(特点、优点、原理)

    转自:https://www.cnblogs.com/hoojo/archive/2011/06/01/2066119.html 介绍:MongoDB是一个基于分布式文件存储的数据库.由C++语言编写 ...

  10. BZOJ4479 [JSOI2013] 吃货jyy 解题报告(三进制状态压缩+欧拉回路)

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4479 Description [故事背景]作为JSOI的著名吃货,JYY的理想之一就是吃 ...