2015 多校联赛 ——HDU5386(暴力)
来源:互联网 发布:全知之眼纹身意义 编辑:程序博客网 时间:2024/06/05 03:59
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
给你一个初始矩阵和目标矩阵,包含‘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 200050int 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;}
0 0
- 2015 多校联赛 ——HDU5386(暴力)
- hdu5386(暴力)
- hdu5386 Cover(暴力,观察)
- 2015 多校联赛 ——HDU5289(二分+ST)
- 2015多校联赛 ——HDU5288(数学)
- 2015 多校联赛 ——HDU5299(树删边)
- 2015 多校联赛 ——HDU5305(搜索)
- 2015 多校联赛 ——HDU5303(贪心)
- 2015 多校联赛 ——HDU5301(技巧)
- 2015 多校联赛 ——HDU5319(模拟)
- 2015 多校联赛 ——HDU5323(搜索)
- 2015 多校联赛 ——HDU5316(线段树)
- 2015 多校联赛 ——HDU5325(DFS)
- 2015 多校联赛 ——HDU5302(构造)
- 2015 多校联赛 ——HDU5335(Walk out)
- 2015 多校联赛 ——HDU5334(构造)
- 2015 多校联赛 ——HDU5344(水)
- 2015 多校联赛 ——HDU5349(水)
- java 实现显示屏上字符串滚动显示的效果
- 小白学开发(iOS)OC_ Foundation之NSString类(2015-08-11)
- C语言学生管理系统
- Spring注入集合属性
- Android ViewPager无限滑动(支持左右,无传入数量限制)方式一
- 2015 多校联赛 ——HDU5386(暴力)
- I NEED A OFFER!(1203)
- objective-c学习笔记之属性特性(assign , retain , copy , readonly , readwrite , atomic , nonatomic)
- 20150813
- PreparedStatement JDBC的预加载
- URAL 1057 Amount of Degrees(数位统计)
- DAO
- 深入理解JVM—JVM内存模型
- 反转链表