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
这题看了题解后。感觉挺水的。。由于保证有解,所以能够从后面往前推,遇到整行的颜色和当中没有訪问过的一个操作一样的时候。就把这一行的数都变为0(即随意颜色。由于前面的颜色会被后面的覆盖),当矩阵所有为0就输出结果。 这里假设用set存储的话注意操作符的定义,由于假设定义为x或者y间的比較。可能会把一些同样的操作删除掉。导致WA.
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
int gra[106][106],c[600];
struct node{
int f,x,y,idx;
}b,temp;
bool operator <(node a,node b){
return a.idx<b.idx;
} set<node>myset;
set<node>::iterator it; int main()
{
int n,m,i,j,T,sum,a,x,y,tot,flag,f,t,flag1,idx,num1;
char s[10];
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
sum=n*n;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
scanf("%d",&a);
}
}
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
scanf("%d",&gra[i][j]);
}
}
myset.clear();
for(i=1;i<=m;i++){
scanf("%s%d%d",s,&x,&y);
if(s[0]=='L'){
b.f=1;
}
else b.f=0;
b.x=x;b.y=y;b.idx=i;
myset.insert(b);
}
t=0;
while(1)
{
//if(myset.size()==0)break;// || sum==0
if(sum==0)break;
flag=0;
for(it=myset.begin();it!=myset.end();it++){
temp=*it;
x=temp.x;y=temp.y;f=temp.f;idx=temp.idx;
if(f==1){
flag1=1;tot=0;
for(i=1;i<=n;i++){
if(gra[i][x]==0)continue;
if(gra[i][x]==y)tot++;
else{
flag1=0;break;
}
}
if(tot==0 || flag1==0)continue; flag=1;
for(i=1;i<=n;i++){
if(gra[i][x]==0)continue;
else {gra[i][x]=0;sum--;}
}
t++;c[t]=idx;
myset.erase(it);break;
} else if(f==0){
flag1=1;tot=0;
for(i=1;i<=n;i++){
if(gra[x][i]==0)continue;
if(gra[x][i]==y)tot++;
else{
flag1=0;break;
}
}
if(tot==0 || flag1==0)continue; flag=1;
for(i=1;i<=n;i++){
if(gra[x][i]==0)continue;
else {gra[x][i]=0;sum--;}
}
t++;c[t]=idx;
myset.erase(it);break;
}
}
if(!flag)break;
}
for(i=1;i<=m;i++){
flag=0;
for(j=1;j<=t;j++){
if(i==c[j]){
flag=1;break;
}
}
if(flag==0){
printf("%d ",i);
}
}
for(i=t;i>=1;i--){
if(i==1)printf("%d\n",c[i]);
else printf("%d ",c[i]);
}
}
return 0;
}
/*
100
3 7
2 2 1
2 3 3
2 1 3
3 2 2
1 1 2
1 1 1
L 2 3
L 1 3
H 2 1
H 3 3
L 4 3
L 3 2
H 3 1
*/

hdu5386 Cover的更多相关文章

  1. Dancing Links and Exact Cover

    1. Exact Cover Problem DLX是用来解决精确覆盖问题行之有效的算法. 在讲解DLX之前,我们先了解一下什么是精确覆盖问题(Exact Cover Problem)? 1.1 Po ...

  2. img及父元素(容器)实现类似css3中的background-size:contain / background-size:cover

    img及父元素(容器)实现类似css3中的background-size:contain / background-size:cover <!DOCTYPE html> <html ...

  3. 集合覆盖 顶点覆盖: set cover和vertex cover

    这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...

  4. poj 1266 Cover an Arc.

    http://poj.org/problem?id=1266 Cover an Arc. Time Limit: 1000MS   Memory Limit: 10000K Total Submiss ...

  5. HUST 1017 - Exact cover (Dancing Links 模板题)

    1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0 ...

  6. background-size的两个属性:cover和contain

    两种都不会造成图片失真,其中: (1)cover:相当于宽度等于元素的宽度,高度设为auto: (2)contain:相当于高度等于元素的高度,宽度设为auto: 例如:设置一个高度和宽度都为300p ...

  7. Dancing Link --- 模板题 HUST 1017 - Exact cover

    1017 - Exact cover Problem's Link:   http://acm.hust.edu.cn/problem/show/1017 Mean: 给定一个由0-1组成的矩阵,是否 ...

  8. CSS3 background-size 属性值:cover

    当设置值为cover,可以呈现出图片铺满浏览器内容的视觉效果 实例 规定背景图像的尺寸: div { background:url(img_flwr.gif); background-size:80p ...

  9. background-size的cover和content的用法

    background-size:cover; 表示背景图拉伸布满,如果在手机上做的话,背景图片会拉大,失真.这样做不妥 background-size:content; 表示背景图片在内容区域正常显示 ...

随机推荐

  1. 辨异 —— Java 中的抽象类和接口

    接口优于抽象类.-- <Effective Java>(Item 18) 0. 语法区别 抽象类允许给出某些方法的实现,接口不允许: 为了实现由抽象类定义的类型(type),类必须成为抽象 ...

  2. Javascript技巧之不要用for in语句对数组进行遍历

    一,为什么不要用for in语句 jqModal这个jquery插件估计很多人都使用过,在jqModal源码内部,有一个函数为hs,其中有个嵌套循环如下, for(var i in {jqmShow: ...

  3. java环境的配置和求最大子数组

    做java开发的朋友,都应该有一个适合自己的开发环境,而eclipse就是这么一个适合java开发的集成环境,完全免费,是java开发人员的必备平台.在安装eclipse之前需要安装JDK, JDK是 ...

  4. Linux查找并杀死僵尸进程

    1.查看系统是否有僵尸进程 使用Top命令查找,当zombie前的数量不为0时,即系统内存在相应数量的僵尸进程. 2.定位僵尸进程 使用命令ps -A -ostat,ppid,pid,cmd |gre ...

  5. HTML中href、src区别

    href是Hypertext Reference的缩写,表示超文本引用.用来建立当前元素和文档之间的链接.常用的有:link.a.例如: <link href="reset.css&q ...

  6. postgresql 备份(pg_dump,pg_restore)

    PG提供物理备份和逻辑备份(本篇主要讲逻辑备份)物理备份:WAL热备份逻辑备份:pg_dump,pg_dumpall,恢复时pg_restore 查看帮助命令: pg_dump --help 跟MyS ...

  7. FastDFS介绍(非原创)

    文章大纲 一.FastDFS介绍二.FastDFS安装与启动(Linux系统)三.Java客户端上传图片四.参考文章   一.FastDFS介绍 1. 什么是FastDFS FastDFS是用C语言编 ...

  8. .net core发布到IIS后502.5错误

    net core 在win7系统发布后,出现在502.5错误. 打开“开始”菜单,搜索“事件查看器”,然后选择“事件查看器”应用. 在“事件查看器”中,打开“Windows 日志”节点. 选择“应用程 ...

  9. (转载)Activity-数据状态的保存

    由于手机是便捷式移动设备,掌握在用户的手中,它的展示方向我们是无法预知的,具有不确定性.平时我们拿着手机多数为竖屏,但有时候我们感觉累了也会躺着去使用手机,那么这时手机屏幕的展示方向可能已经被用户切换 ...

  10. Struts2框架学习(二)——访问流程及架构

    1.Struts2的执行流程 从客户端发送请求过来,先经过前端控制器(核心过滤器StrutsPrepareAndExecuteFilter)过滤器中执行一组拦截器(一组拦截器就会完成部分功能代码),拦 ...