2015 多校联赛 ——HDU5386(暴力)
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
给你一个初始矩阵和目标矩阵,包含‘L’ , ' H' 两个操作, ‘L x y’ 表示把第x列全赋值成y, ‘Hx y’ 表示把第x行全赋值成y。
求怎样的顺序可以得出目标矩阵。
倒着求解,在目标矩阵上你肯定能找到最后一个操作,这样倒推出答案即可
#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;
#define maxn 200050 int T,n,m,t,k,l,tot,j;
int a[105][105];
int b[505],c[505],ans[505];
char p[505],ch; int main()
{
scanf("%d",&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]); t = 0;
tot = 0;
for(int i = 1; i <= m; i++)
{
for(ch=getchar(); ch!='H'&&ch!='L'; ch=getchar());
p[i] = ch;
scanf("%d%d",&b[i],&c[i]);
} while(tot < m)
{
for(int i=1;i<=m;++i)
if(b[i])
{
int t = b[i];
if(p[i] == 'L')
{
for(j = 1; j <= n; j++)
if(a[j][t] && a[j][t] != c[i])
break;
if(j > n)
{
for(int j = 1; j <= n; j++)
a[j][t] = 0;
b[i] = 0;
ans[tot++] = i;
}
}
else
{
for(j = 1; j <= n; j++)
if(a[t][j] && a[t][j] != c[i])
break;
if(j > n)
{
for(int j = 1; j <= n; j++)
a[t][j] = 0;
b[i] = 0;
ans[tot++] = i;
}
}
}
} for(int i=m-1; i>=0; --i)printf("%d ",ans[i]);
printf("\n");
}
return 0;
}
2015 多校联赛 ——HDU5386(暴力)的更多相关文章
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 2015 多校联赛 ——HDU5302(构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- 2015 多校联赛 ——HDU5316(线段树)
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...
- 2015 多校联赛 ——HDU5323(搜索)
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 2015 多校联赛 ——HDU5319(模拟)
Painter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- 2015 多校联赛 ——HDU5301(技巧)
Your current task is to make a ground plan for a residential building located in HZXJHS. So you must ...
- 2015 多校联赛 ——HDU5303(贪心)
Delicious Apples Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
随机推荐
- Ubuntu登陆密码忘记
在VMware中安装了Ubuntu 10.04,经过了一段时间,再次登录的时候居然进不去了, 一开始不知道怎样在虚拟机中进入到Grub启动界面,网上搜索了一番,按照以下步骤重新为用户设定了新密码. 重 ...
- 【转载】NetFPGA-1G-CML从零开始环境配置
##环境 深度Linux ###环境配置 ```bash sudo apt-get install libsigc++ sudo apt-get install qgit sudo apt-get i ...
- Java 后端微信小程序支付demo (网上说的坑里面基本上都有)
Java 后端微信小程序支付 一.遇到的问题 1. 商户号该产品权限未开通,请前往商户平台>产品中心检查后重试 2.签名错误 3.已经调起微信统一下单接口,可以拿到预支付ID,但是前端支付的时候 ...
- bzoj千题计划242:bzoj4034: [HAOI2015]树上操作
http://www.lydsy.com/JudgeOnline/problem.php?id=4034 dfs序,树链剖分 #include<cstdio> #include<io ...
- jQuery 写的textarea输入字数限制
//先判断浏览器是不是万恶的IE var bind_name = 'input';//默认事件 if (navigator.userAgent.indexOf(" ...
- C++ 实现一个信号量
C++ 实现一个信号量 信号量有很多应用场景,事实上只要是生产者-消费者模型,一般都需要一个信号量来控制. POSIX接口是有PV信号量API的.但C++标准没有.下面是一个PV信号量的简单实现.有些 ...
- Python模块configparser(操作配置文件ini)
configparser模块提供对ini文件的增删改查方法. ini文件的数据格式: [name1] attribute1=value1 attribute2=value2 [name2] attri ...
- Python内置函数(62)——exec
英文文档: exec(object[, globals[, locals]]) This function supports dynamic execution of Python code. obj ...
- Python-迭代器&生成器&装饰器&软件目录结构规范-Day5
目录Day-Python-迭代器&生成器 21.生成器 21.1.生成器引入 21.2.生成器作用 31.3.创建生成器的方法 31.4.用函数来实现复杂的生成器 51.5.把函数变成生成器通 ...
- gradle入门(1-3)使用gradle开发一个发布版本
需求描述 1.使用Maven central仓库.2.使用Log4j写入日志.3.包含单元测试,保证正确的信息返回,单元测试必须使用JUnit编写.4.创建一个可执行的Jar文件. 我们来看一下怎样实 ...