HDU 5386 Cover(模拟)
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
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.
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
i-th integer x show that the rank of x-th operating is i
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
5 2 4 3 1
题意:给出两个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(模拟)的更多相关文章
- hdu 5386 Cover (暴力)
hdu 5386 Cover Description You have an matrix.Every grid has a color.Now there are two types of oper ...
- HDU 5386 Cover
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5386 题目大意:给一个初始矩阵(n×n).一个目标矩阵(n×n)和m个操作,要求找到一种操作顺序,使初 ...
- HDU 6311 Cover (无向图最小路径覆盖)
HDU 6311 Cover (无向图最小路径覆盖) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- 暴力/思维 HDOJ 5386 Cover
题目传送门 /* 题意:给出刷墙的所有的方法,求一种顺序,使得原矩阵刷成目标矩阵 暴力:(题解)我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可 */ /* ...
- hdoj 5386 Cover
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5386 倒着推的一个挺暴力的题,看着和数学有关系,然而并没有, 不要一看到含有数学元素就考虑这是一个数学 ...
- HDU 4121 Xiangqi 模拟题
Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...
- hdu 5071 Chat(模拟)
题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...
- hdu 4740【模拟+深搜】.cpp
题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...
- HDU 2568[前进]模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...
随机推荐
- ZBrush中独特功能Projection Master
Projection Master可以理解为投影大师,它是ZBrush®的一个独特功能,该功能可以让用户使用所有的2D和2.5D笔刷工具在3D模型上进行雕刻.纹理绘制和其他的操作. 简单来说,Proj ...
- vue 事件参数传$event打印当前组件
<template> <div class="hello"> <button v-on:click.once="getinfo($event ...
- 微软的鼠标 Microsoft mouse
微软是做软件出身的厂商, 所以微软开发的软件质量毋庸置疑,Windows操作系统还有诸如Office的办公软件拥有庞大的用户群. 微软家的Visual Studio也被号称宇宙最强IDE,我个人也每天 ...
- 嵌入式表单字段中的内容可能被server更改以删除不安全的内容。是否要又一次载入您的页面以查看保存结果?
嵌入式表单字段中的内容可能被server更改以删除不安全的内容.是否要又一次载入您的页面以查看保存结果? 近期有朋友问到,当他在SharePoint首页上进行编辑时.插入一段代码. 完 ...
- HTML5实战与剖析之媒体元素(3、媒体元素的事件及方法)
HTML5中的媒体元素除了拥有非常多的属性之外,video标签和audio标签还能够出发非常多事件和方法. 这些方法监控着不同的属性的变化,这些变化有可能是媒体播放的结果,也可能是用户操作媒体的结果. ...
- 设计模式-策略模式(Go语言描写叙述)
好久没有更新博客了.近期也是在忙着充电,今天这篇博客開始,我们来了解一下设计模式. 设计模式 那什么是设计模式呢?首先来看看我从百科上copy下来的概念吧. 设计模式/软件设计模式(Design pa ...
- 一入python深似海--python之道
python社区不乏幽默.先来看"python之道"这首诗. 导入this包: import this 输出是一首诗,这首诗总结了Python的风格,能够指导Python程序猿的编 ...
- TCO14 1B L3: EagleInZoo, dp,tree
题目:http://community.topcoder.com/stat?c=problem_statement&pm=13117&rd=15950 看到树,又是与节点有关,通常是d ...
- 手动配置三大框架整合:Spring+Struts2+mybatis
如今主流的项目框架中,数据库持久层有可能不是hibernate,而是mybatis或者ibatis,事实上它们都是一样的,以下我来把环境搭建一下: [导入相关jar包]新建web项目projectms ...
- Hadoop入门进阶步步高(二)-文件夹介绍
二.Hadoop文件夹结构 这里重点介绍几个文件夹bin.conf及lib文件夹. 1.$HADOOP_HOME/bin文件夹 文件名 说明 hadoop 用于运行hadoop脚本命令,被hadoop ...