暴力/思维 HDOJ 5386 Cover
/*
题意:给出刷墙的所有的方法,求一种顺序,使得原矩阵刷成目标矩阵
暴力:(题解)我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可
*/
/************************************************
* Author :Running_Time
* Created Time :2015-8-13 21:25:07
* File Name :G.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e2 + ;
const int MAXM = 5e2 + ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
int a[MAXN][MAXN];
int b[MAXM], c[MAXM];
char op[MAXM];
int ans[MAXM]; int main(void) { //HDOJ 5386 Cover
int T; scanf ("%d", &T);
while (T--) {
int n, m; scanf ("%d%d", &n, &m);
for (int i=; i<=n; ++i) {
for (int j=; j<=n; ++j) {
scanf ("%d", &a[i][j]);
}
}
for (int i=; i<=n; ++i) {
for (int j=; j<=n; ++j) {
scanf ("%d", &a[i][j]);
}
}
for (int i=; i<=m; ++i) {
char ch;
for (ch=getchar (); ch!='H'&&ch!='L'; ch=getchar ()) ;
op[i] = ch; scanf ("%d%d", &b[i], &c[i]);
} int t = ;
while (t < m) {
for (int i=; i<=m; ++i) {
if (!b[i]) continue;
if (op[i] == 'H') {
int x = b[i]; bool flag = true;
for (int j=; j<=n; ++j) {
if (a[x][j] && a[x][j] != c[i]) {
flag = false; break;
}
}
if (flag) {
ans[++t] = i; b[i] = ;
for (int j=; j<=n; ++j) a[x][j] = ;
}
}
else {
int y = b[i]; bool flag = true;
for (int j=; j<=n; ++j) {
if (a[j][y] && a[j][y] != c[i]) {
flag = false; break;
}
}
if (flag) {
ans[++t] = i; b[i] = ;
for (int j=; j<=n; ++j) a[j][y] = ;
}
}
}
} for (int i=m; i>=; --i) printf ("%d%c", ans[i], (i == ) ? '\n' : ' ');
} return ;
}
暴力/思维 HDOJ 5386 Cover的更多相关文章
- hdoj 5386 Cover
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5386 倒着推的一个挺暴力的题,看着和数学有关系,然而并没有, 不要一看到含有数学元素就考虑这是一个数学 ...
- hdu 5386 Cover (暴力)
hdu 5386 Cover Description You have an matrix.Every grid has a color.Now there are two types of oper ...
- 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)
湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...
- DFS/BFS+思维 HDOJ 5325 Crazy Bobo
题目传送门 /* 题意:给一个树,节点上有权值,问最多能找出多少个点满足在树上是连通的并且按照权值排序后相邻的点 在树上的路径权值都小于这两个点 DFS/BFS+思维:按照权值的大小,从小的到大的连有 ...
- 模拟+思维 HDOJ 5319 Painter
题目传送门 /* 题意:刷墙,斜45度刷红色或蓝色,相交的成绿色,每次刷的是连续的一段,知道最终结果,问最少刷几次 模拟+思维:模拟能做,网上有更巧妙地做法,只要前一个不是一样的必然要刷一次,保证是最 ...
- HDU 5386 Cover(模拟)
Cover Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Subm ...
- 【洛谷】P1275 魔板(暴力&思维)
题目描述 有这样一种魔板:它是一个长方形的面板,被划分成n行m列的n*m个方格.每个方格内有一个小灯泡,灯泡的状态有两种(亮或暗).我们可以通过若干操作使魔板从一个状态改变为另一个状态.操作的方式有两 ...
- HDU 5386 Cover
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5386 题目大意:给一个初始矩阵(n×n).一个目标矩阵(n×n)和m个操作,要求找到一种操作顺序,使初 ...
- codeforce 985B Switches and Lamps(暴力+思维)
Switches and Lamps time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 【ZJOI2017 Round1练习&BZOJ4773】D3T1 cycle(最小负环,倍增)
题意:给定一个带权有向图,求点数最小的负环. 2 ⩽ n ⩽ 3000 ⩽ m ⩽ n(n - 1)1 ⩽ ui,vi ⩽ nabs(w[j])<= 10^4 思路:倍增思想 设d[i,j,k] ...
- C++ fill 和memset
以下内容来自www.cplusplus.com--------------------------------------------------- FILL: template <class ...
- POJ3728 The merchant解题报告
Description There are N cities in a country, and there is one and only one simple path between each ...
- nginx: [emerg] unknown directive "聽" in D:\software03\GitSpace\cms\nginx-1.14.0/conf/nginx.conf:36
nginx: [emerg] unknown directive "聽" in D:\software03\GitSpace\cms\nginx-1.14.0/conf/nginx ...
- 在springBoot与quartz 整合中 @Transaction 失效
问题1::springBoot在与quartz 整合时,使用@Transaction 注解时事务失效 解决方案:创建一个类使用@component被spring管理 ,使用@Transaction标识 ...
- 基于 Java 的开源网络爬虫框架 WebCollector
原文:https://www.oschina.net/p/webcollector
- jmeter的master-slave模式
要求: 1.相同的jmeter版本 2.最好相同的java版本 jmeter可以通过master-slave的方式实现更大的并发,但是作为master的机器将会消耗更多的资源,因为所有的slave的压 ...
- FlashBuilder 4.7 非正常关闭导致的不能启动的解决的方法
停电.或者卡死.FB就不能正常启动了. 以下是老外给出的方法,好用: 进入.metadata/.plugins/org.eclipse.core.resources 文件夹 删除.snap文件 假设是 ...
- Android ListView的item点击无响应的解决方法
假设listitem里面包含button或者checkbox等控件,默认情况下listitem会失去焦点,导致无法响应item的事件,最经常使用的解决的方法 是在listitem的布局文件里设置des ...
- NSSet所有API学习。
/****************集合(NSSet)和数组(NSArray)有相似之处,都是存储不同的对象的地址.只是NSArray是有序的集合,NSSet是无序的集合,同一时候NSSet能够保证数据 ...