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. nyoj--92--图像有用区域(模拟)

    图像有用区域 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 "ACKing"同学以前做一个图像处理的项目时,遇到了一个问题,他需要摘取出图片中某个黑 ...

  2. 如何让音频跟视频在ios跟android上自动播放

    如何让音频跟视频在ios跟android上自动播放 <audio autoplay ><source src="audio/alarm1.mp3" type=&q ...

  3. php navigat备份

    点击查询->新建查询->写sql查询出更新的数据部分(根据时间等条件) -> 点击上方工具菜单栏的导出向导 ,然后就可以根据选择导出文件了可以导出sql脚本excel等很多,绝对有你 ...

  4. Linux Shell Scripting Cookbook 读书笔记 4

    正则, grep 1. 正则表达式  正则表达式  描述  示例 ^ 行起始标记  ^hell匹配以hell开头的行 $ 行尾标记  test$匹配以test结尾的行 . 匹配任意一个字符  hell ...

  5. 在量化金融中15个最流行的Python数据分析库

    Python是当今应用最广泛的编程语言之一,以其效率和代码可读性著称.作为一个科学数据的编程语言,Python介于R和java之间,前者主要集中在数据分析和可视化,而后者主要应用于大型应用.这种灵活性 ...

  6. Selenium等待某个元素出现之隐式等待

    找不到元素这个问题困扰了两天了,一直怀疑是页面div层次太多,定位不准确.于是就从table开始到最后一层精确定位,仍然找不元素.怎么办,在网上搜索答案,说是可以加个隐式试试,于是在执行前加了一句等待 ...

  7. 一次显式GC导致的High CPU问题处理过程

    项目现场反馈系统出现性能问题,具体表现为:所有的客户端响应极其卡顿. 第一反应推测,难道是DB层面出现阻塞?检查v$session会话状态及等待类型未见异常,应该可以排除DB层面原因导致的可能. 继续 ...

  8. Java 系列之spring学习--spring搭建(一)

    一.新建maven项目 二.引入spring jar包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xs ...

  9. css3 边框、背景、文本效果

    浅玩CSS3 边框.背景.文本效果 一.边框 box-shadow box-shadow: h-shadow v-shadow blur spread color inset(ontset); //h ...

  10. 有关Gradle Network is unreachable: connect的报错

    项目Gradle   Errer:Network is unreachable: connect 同时还有as的 报错 Internal HTTP server disabled: Cannot st ...