hdu 5386 Cover (暴力)
hdu 5386 Cover
Description
You have an 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 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
For each case:
First line has two integer ,
Then lines,every line has integers,describe the initial matrix
Then lines,every line has integers,describe the goal matrix
Then lines,every line describe an operating
Output
For each case,print a line include integers.The i-th integer x show that the rank of x-th operating is
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
题目大意:给你n×n的初始图形,和目标图形,还有m个操作,操作和一把一行或一列变成一种颜色。如今问使初始图形变成目标图形的操作的顺序。每一个操作都要用上,且一定有解。
解题思路:初始图形没实用。直接从目标图形開始进行操作。
对于一个操作。推断该操作相应的那一行或一列的颜色,是否除0之外所有都是与该操作变换的颜色同样,是的话,将那一行或一列所有变为0,而且记录该操作,最后逆序输出。
注意,把所有操作遍历一遍是不够的。由于有一些操作是要在别的操作已进行过的基础上才干进行。所以在遍历操作的外层要再加一层循环(cnt
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
const int N = 205;
const int M = 2005;
typedef long long ll;
int ans[M];
int G1[N][N], G2[N][N];
struct Node{
int pos, val, id;
}H[M], L[M];
int n, m, cntH, cntL;
void init() {
memset(L, 0, sizeof(L));
memset(H, 0, sizeof(H));
memset(G2, 0, sizeof(G2));
cntH = cntL = 0;
}
void input() {
scanf("%d %d", &n, &m);
int a, b;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &G1[i][j]);
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &G2[i][j]);
}
}
char s[20];
for (int i = 1; i <= m; i++) {
scanf("%s", s);
scanf("%d %d", &a, &b);
if (strcmp(s, "H") == 0) {
H[cntH].pos = a;
H[cntH].val = b;
H[cntH++].id = i;
} else {
L[cntL].pos = a;
L[cntL].val = b;
L[cntL++].id = i;
}
}
}
void solve() {
int cnt = 0;
while (cnt < m) {
for (int i = 0; i < cntH; i++) {
int k = H[i].pos, flag = 1;
if (!k) continue;
for (int j = 1; j <= n; j++) {
if(G2[k][j] && G2[k][j] != H[i].val) {
flag = 0;
break;
}
}
if(flag) {
ans[cnt++] = H[i].id;
for(int j = 1; j <= n; j++) G2[k][j] = 0;
H[i].pos = 0;
}
}
for (int i = 0; i < cntL; i++) {
int k = L[i].pos, flag = 1;
if (!k) continue;
for(int j = 1; j <= n; j++) {
if(G2[j][k] && G2[j][k] != L[i].val) {
flag = 0;
break;
}
}
if(flag) {
ans[cnt++] = L[i].id;
for(int j = 1; j <= n; j++) G2[j][k] = 0;
L[i].pos = 0;
}
}
}
for (int i = m - 1; i >= 1; i--) printf("%d ", ans[i]);
printf("%d\n", ans[0]);
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
init();
input();
solve();
}
return 0;
}
hdu 5386 Cover (暴力)的更多相关文章
- HDU 5386 Cover
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5386 题目大意:给一个初始矩阵(n×n).一个目标矩阵(n×n)和m个操作,要求找到一种操作顺序,使初 ...
- HDU 5386 Cover(模拟)
Cover Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Subm ...
- 暴力/思维 HDOJ 5386 Cover
题目传送门 /* 题意:给出刷墙的所有的方法,求一种顺序,使得原矩阵刷成目标矩阵 暴力:(题解)我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可 */ /* ...
- HDU 6311 Cover (无向图最小路径覆盖)
HDU 6311 Cover (无向图最小路径覆盖) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDU 5386 暴力
题目 也是个坑题,可惜没有发现这是个水题,被矩阵的气势吓住了,其实后来做出来的人挺多,就应该想到没那么难了.(两个队友陷入DP无法自拔,没有想换题的打算). 题意:告诉初始矩阵,目的矩阵,告诉n个步骤 ...
- hdoj 5386 Cover
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5386 倒着推的一个挺暴力的题,看着和数学有关系,然而并没有, 不要一看到含有数学元素就考虑这是一个数学 ...
- HDU 5510 Bazinga 暴力匹配加剪枝
Bazinga Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5510 ...
- HDU 5522 Numbers 暴力
Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5522 ...
- hdu 5077 NAND(暴力打表)
题目链接:hdu 5077 NAND 题目大意:Xiaoqiang要写一个编码程序,然后依据x1,x2,x3的值构造出8个字符.如今给定要求生成的8个字符.问 说Xiaoqiang最少要写多少行代码. ...
随机推荐
- zabbix4.2学习笔记--zabbix安装
环境 系统信息 发行版 版本 ip 关系 主机名 centos 7.5 192.168.181.135 服务端 server centos 7.5 192.168.181.136 客户端 client ...
- 布尔上下文,这里misreading返回的是来源列表中元素的个数,如果列表中2个值都是undef,则列表元素个数是1: while( $misreading = (my $test_consideration, my $english_pragma) = each %map_function){
布尔上下文,这里misreading返回的是来源列表中元素的个数, 列表赋值运算的值将会是来源列表中元素的个数,空列表表示0,如果列表中2个值都是undef,则列表元素个数是1 布尔上下文,这里mis ...
- base64记载
一丶 js /** * * Base64 encode / decode * * @author haitao.tu * @date 2010-04-26 * @email tuhaitao@foxm ...
- JS日期,金钱处理
一丶获取两个时间的天数 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...
- A10. JVM 对象
[概述] 首先需要了解对象在内存中的存储布局,其次需要了解对对象的访问定位. [对象的内存布局] 在 HotSpot 虚拟机中,对象在内存中存储的布局可以分为 3 块区域:对象头(Header).实例 ...
- RestTemplate接收HashMap变为LinkedHashMap,RestTemplate接收数据后转成json数据出现反斜杠
使用postForObject方法远程调用接口,正常会返回List<HashMap>,然而实际上却返回List<LinkedHashMap>,同时将此数据进行json转换,变成 ...
- 笔试算法题(33):烙饼排序问题 & N!阶乘十进制末尾0的个数二进制最低1的位置
出题:不同大小烙饼的排序问题:对于N块大小不一的烙饼,上下累在一起,由于一只手托着所有的饼,所以仅有一只手可以翻转饼(假设手足够大可以翻转任意块数的 饼),规定所有的大饼都出现在小饼的下面则说明已经排 ...
- mac apache 配置
mac系统自带apache这无疑给广大的开发朋友提供了便利,接下来是针对其中的一些说明 一.自带apache相关命令 1. sudo apachectl start 启动服务,需要权限,就是你计算机的 ...
- [Python3网络爬虫开发实战] 1.4.1-MySQL的安装
MySQL是一个轻量级的关系型数据库,本节中我们来了解下它的安装方式. 1. 相关链接 官方网站:https://www.mysql.com/cn 下载地址:https://www.mysql.com ...
- 转:Centos7安装zabbix3.4超详细步骤解析
安装前准备: 1.1 安装依赖包: yum -y install wget net-snmp-devel OpenIPMI-devel httpd openssl-devel java lrzsz f ...