HDU 5386 Cover
来源:互联网 发布:网络统考成绩查询2017 编辑:程序博客网 时间:2024/06/07 03:01
Cover
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Special Judge
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 arem 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.
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
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 integern ,m
Thenn lines,every line has n integers,describe the initial matrix
Thenn lines,every line has n integers,describe the goal matrix
Thenm lines,every line describe an operating
1≤color[i][j]≤n
T=5
1≤n≤100
1≤m≤500
For each case:
First line has two integer
Then
Then
Then
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
13 52 2 1 2 3 3 2 1 3 3 3 3 3 3 3 3 3 3 H 2 3L 2 2H 3 3H 1 3L 2 3
Sample Output
5 2 4 3 1
想复杂了,暴力解决即可,原始数组没有,从目标数组倒着思考每一个操作,多次重复,排序即可。
#pragma comment(linker, "/STACK:1024000000,1024000000")#include <set>#include <map>#include <stack>#include <cmath>#include <queue>#include <cstdio>#include <bitset>#include <string>#include <vector>#include <iomanip>#include <cstring>#include <iostream>#include <algorithm>#include <functional>#define inf 0x7fffffff#define maxn 100010using namespace std;struct OP{ char s; int c, v;}op[550];int a[110][110];int b[110][110];int vis[550], ran[550];int main(){ int t; scanf("%d", &t); while (t--) { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%d", &a[i][j]); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%d", &b[i][j]); } } memset(vis, 0, sizeof(vis)); for (int i = 0; i < m; i++) { scanf(" %c %d %d", &op[i].s, &op[i].c, &op[i].v); } int cnt = 1; while (cnt <= m) { for (int i = 0; i < m; i++) { if (vis[i]) { continue; } if (op[i].s == 'H') { int flag = 0; int pos = op[i].c-1; for (int j = 0; j < n; j++) { if (b[pos][j] != 0 && b[pos][j] != op[i].v) { flag = 1; break; } } if (flag == 0) { vis[i] = 1; ran[cnt++] = i; for (int j = 0; j < n; j++) { b[pos][j] = 0; } } } else { int flag = 0; int pos = op[i].c-1; for (int j = 0; j < n; j++) { if (b[j][pos] != 0 && b[j][pos] != op[i].v) { flag = 1; break; } } if (flag == 0) { vis[i] = 1; ran[cnt++] = i; for (int j = 0; j < n; j++) { b[j][pos] = 0; } } } } } for (int i = m; i >= 1; i--) { if (i != 1) { printf("%d ", ran[i] + 1); } else { printf("%d\n", ran[i] + 1); } } } return 0;}
0 0
- HDU 5386 Cover(暴力)
- HDU 5386 Cover
- HDU 5386 Cover
- Hdu 5386 Cover 拓扑排序
- hdu 5386 Cover (暴力)
- hdu 5386 Cover 暴力模拟
- HDU 5386 Cover(模拟)
- hdu 5386 Cover(暴力)
- HDU 5386 Cover 覆盖染色
- HDU 5386 Cover (MUT #8 模拟暴力)
- hdu 5386 Cover (逆向暴力模拟)
- hdu 5386 Cover(逆向思维+模拟)
- hdu 5386 Cover(暴搞+队列)
- hdu 6150 Vertex Cover
- hdu 5386 Cover(暴力求解+想法题)
- HDU 5386 Cover (2015年多校比赛第8场)
- 2015多校第8场 HDU 5386 Cover 贪心,暴力,玄学
- HDU-4145 Cover The Enemy
- win10中Django后台admin无法加载CSS等样式
- Docker Tutorial
- CRC校验原理剖析
- netstat 的一些参数
- * 24种设计模式——单例模式
- HDU 5386 Cover
- 追梦
- NYOJ—最少步数( 迷宫)
- ubuntu16.10开启telnet办法
- Python第三方包OpenCV读取MP4格式文件的问题
- BZOJ 1691 [Usaco2007 Dec]挑剔的美食家
- linux errno查看和使用
- Shell学习
- 操作系统之汇编语言(1)