Link:http://acm.hdu.edu.cn/showproblem.php?pid=5386
Cover
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1247 Accepted Submission(s): 430
Special Judge
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 m 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.
For each case:
First line has two integer n , m
Then n lines,every line has n integers,describe the initial matrix
Then n lines,every line has n integers,describe the goal matrix
Then m lines,every line describe an operating
1≤color[i][j]≤n
T=5
1≤n≤100
1≤m≤500
1 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
5 2 4 3 1
1007.Cover
水题,我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可
其实初始矩阵并没有什么卵用
稍微优化下复杂度是O(n2)的,但是为了简易些范围开到了100
AC code:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
#define LL long long
#define MAXN 1000010
using namespace std;
struct node{
char ch[3];
int x;
int y;
}op[MAXN];
int color1[111][111];
int color2[111][111];
bool vis[MAXN];
int ans[MAXN];
int main()
{
//freopen("D:\in.txt","r",stdin);
int n,m,t,i,j,k,cnt;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&color1[i][j]);
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&color2[i][j]);
}
}
for(i=1;i<=m;i++)
{
scanf("%s%d%d",op[i].ch,&op[i].x,&op[i].y);
}
/* for(i=1;i<=m;i++)
{
printf("%s %d %d\n",op[i].ch,op[i].x,op[i].y);
}*/
memset(vis,false,sizeof(vis));
cnt=0;
while(1)
{
for(i=1;i<=m;i++)
{
if(vis[i])
continue;
if(op[i].ch[0]=='H')
{
j=op[i].x;
for(k=1;k<=n;k++)
{
if(color2[j][k]!=0&&color2[j][k]!=op[i].y)
break;
}
if(k==n+1)
{
for(k=1;k<=n;k++)
{
color2[j][k]=0;
}
ans[++cnt]=i;
vis[i]=true;
}
}
else if(op[i].ch[0]=='L')
{
j=op[i].x;
for(k=1;k<=n;k++)
{
if(color2[k][j]!=0&&color2[k][j]!=op[i].y)
break;
}
if(k==n+1)
{
for(k=1;k<=n;k++)
{
color2[k][j]=0;
}
ans[++cnt]=i;
vis[i]=true;
}
}
if(cnt==m)
break;
}
if(cnt==m)
break;
}
for(i=cnt;i>=1;i--)//注意:因为顺序是倒着推出来的,所以输出时也要逆着输出
{
if(i==cnt)
printf("%d",ans[i]);
else
printf(" %d",ans[i]);
}
puts("");
}
return 0;
}
7166



被折叠的 条评论
为什么被折叠?



