hdu5386 棋盘涂色模拟
来源:互联网 发布:淘宝客新手怎么推广 编辑:程序博客网 时间:2024/04/28 08:21
http://acm.hdu.edu.cn/showproblem.php?pid=5386
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
/** hdu5386 模拟 题目大意:给一个棋盘涂色,每次操作给棋盘的某一列或一行涂上一种颜色,给定初始棋盘状态和最终棋盘状态,和一系列操作,请给这些序列排一个顺序 解题思路:初始棋盘其实并没有什么用,我们从最终棋盘入手,每次找到一行或一列颜色全部一样的,如给定操作中有给这一行的如此操作,那么给此操作入队, 依次下去得到一个顺序,输出即可 */ #include <stdio.h>#include <string.h>#include <algorithm>#include <iostream>#include <vector>using namespace std;const int maxn=105;int a[maxn][maxn],n,m,x,y;int judge[maxn*5],flag[maxn*5],num[maxn*5];vector<pair<int,int> >x_vec[105],y_vec[105];char s[10];int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); int x; for(int i=0; i<n*n; i++)scanf("%d",&x); 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++) { x_vec[i].clear(); y_vec[i].clear(); } for(int i=1; i<=m; i++) { scanf("%s%d%d",s,&x,&y); if(s[0]=='H') { x_vec[x].push_back(make_pair(y,i)); } else { y_vec[x].push_back(make_pair(y,i)); } } memset(judge,0,sizeof(judge)); int t=m; while(t) { int ok=0; for(int i=1; i<=n; i++) { int sum=0,cnt=0; memset(flag,0,sizeof(flag)); for(int j=1; j<=n&&sum<=1; j++) { if(a[i][j]==0)continue; if(!flag[a[i][j]]) { flag[a[i][j]]=1; sum++; cnt=a[i][j]; } } if(sum==1) { int len=x_vec[i].size(); for(int j=0; j<len; j++) { if(x_vec[i][j].first==cnt) { ok=1; num[t--]=x_vec[i][j].second; judge[x_vec[i][j].second]=1; break; } } for(int j=1; j<=n; j++) a[i][j]=0; } sum=0,cnt=0; memset(flag,0,sizeof(flag)); for(int j=1; j<=n&&sum<=1; j++) { if(a[j][i]==0)continue; if(!flag[a[j][i]]) { flag[a[j][i]]=1; sum++; cnt=a[j][i]; } } if(sum==1) { int len=y_vec[i].size(); for(int j=0; j<len; j++) { if(y_vec[i][j].first==cnt) { ok=1; num[t--]=y_vec[i][j].second; judge[y_vec[i][j].second]=1; break; } } for(int j=1; j<=n; j++) a[j][i]=0; } } if(ok==0)break; } for(int i=1; i<=n; i++) { int len=x_vec[i].size(); for(int j=0; j<len; j++) { if(judge[x_vec[i][j].second]==0) num[t--]=x_vec[i][j].second; } len=y_vec[i].size(); for(int j=0; j<len; j++) { if(judge[y_vec[i][j].second]==0) num[t--]=y_vec[i][j].second; } } for(int i=1; i<=m; i++) { printf(i==m?"%d\n":"%d ",num[i]); } } return 0;}
0 0
- hdu5386 棋盘涂色模拟
- hdu5386(模拟)
- hdu5386
- hdu5386
- HDU5386
- hdu5386 Cover(逆向思维+模拟)
- noip模拟小象涂色
- 模拟棋盘
- [NOIP模拟赛]涂色方案
- [Noip模拟题]小象涂色
- UVa11994 快乐涂色(暴力模拟)
- POJ2996-棋盘模拟
- 模拟题 : 棋盘游戏
- hdu5386(暴力)
- hdu5386 Cover
- 【NOIP 模拟赛】平均数 涂色游戏 序列题解
- 【NOIP2012模拟10.6】填充棋盘
- 【NOI2017模拟4.5】无限棋盘
- Note_20150814_C++_Function
- 让Excel飞!职场Office效率提升秘籍(第2版)——互动出版网
- NSString & Unicode
- python+selenium测试用例参考
- 虚函数——C++PrimeCr第五版读书笔记
- hdu5386 棋盘涂色模拟
- c#获取程序版本号
- Android 之 Binder与进程间通信
- OwnCloud搭建
- HTML 编辑器
- Microsoft ACE OLEDB 12.0 数据库连接字符串
- node.js 小爬虫
- 应用关闭
- IOS 时间戳