Cover

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1027    Accepted Submission(s): 351
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 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.

 
Input
There are multiple test cases,first line has an integer T
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

 
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
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
 
Sample Output
5 2 4 3 1
 

题目大意:给你一个n*n的矩阵,给你初始矩阵和目标矩阵,然后有m个操作。H x z表示将第x行覆盖为z,L x z表示将第x列覆盖为z,保证是有解。问你这m个操作怎么排,可以让初始矩阵变为目标矩阵。

解题思路:遍历m个操作,如果是行操作,就看该行是否都是所要染的颜色或着是0颜色,如果这一行跟要染的颜色一样,那么就存起来操作,同时把该行全部变为0,。由于不是一次下来就能得到结果,所以用一个变量记录已经有多少个操作已经在结果中,最后逆序输出即为答案。

#include<bits/stdc++.h>
using namespace std;
struct Oper{
int r_,x,col;
}opers[550];
int Map[125][125],ans[550],vis[550];
int main(){
int t,a,n,m;
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);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%d",&Map[i][j]);
}
}
int a,b;
char str[20];
for(int i=1;i<=m;i++){
scanf("%s%d%d",str,&a,&b);
if(str[0]=='H'){
opers[i].r_=1;
opers[i].x=a;
opers[i].col=b;
}else{
opers[i].r_=0;
opers[i].x=a;
opers[i].col=b;
}
}
memset(vis,0,sizeof(vis));
int cnt=0;
while(cnt<m){
for(int i=1;i<=m;i++){
if(!vis[i]){
if(opers[i].r_==1){
int r=opers[i].x,aim=opers[i].col;
int j;
for(j=1;j<=n;j++){
if(Map[r][j]!=aim&&Map[r][j]!=0){
break;
}
}
if(j==n+1){
for(j = 1;j<=n;j++){
Map[r][j]=0;
}
ans[cnt]=i;
cnt++;
vis[i]=1;
}
}else{
int c=opers[i].x,aim=opers[i].col;
int j;
for(j=1;j<=n;j++){
if(Map[j][c]!=aim&&Map[j][c]!=0){
break;
}
}
if(j==n+1){
for(j = 1;j<=n;j++){
Map[j][c]=0;
}
ans[cnt]=i;
cnt++;
vis[i]=1;
}
}
}
}
}
printf("%d",ans[cnt-1]);
for(int i=cnt-2;i>=0;i--){
printf(" %d",ans[i]);
}printf("\n");
}
return 0;
}

  

 

HDU——Cover——————【技巧】的更多相关文章

  1. hdu 5265 技巧题 O(nlogn)求n个数中两数相加取模的最大值

    pog loves szh II Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)

    http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...

  3. HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)

    传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...

  4. hdu 4864 Task (贪心 技巧)

    题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...

  5. HDU 6311 Cover (无向图最小路径覆盖)

    HDU 6311 Cover (无向图最小路径覆盖) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...

  6. HDU 5884 Sort(二分答案+计算WPL的技巧)

    Sort Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  7. hdu 5386 Cover (暴力)

    hdu 5386 Cover Description You have an matrix.Every grid has a color.Now there are two types of oper ...

  8. HDU 6150 - Vertex Cover | 2017 中国大学生程序设计竞赛 - 网络选拔赛

    思路来自 ICPCCamp /* HDU 6150 - Vertex Cover [ 构造 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 给了你一个贪心法找最小覆盖的算法,构造一组 ...

  9. HDU -2674 N!Again(小技巧)

    这道题有个小技巧,就是既然是n!,那么对2009求余,只要大于2009!,那么一定是0,在仔细想想会发现,根本到不了2009,只要到2009的最大质因数就行了,为什么呢?因为最大质因数是最大的一个不能 ...

随机推荐

  1. 【C#】 创建和调用webapi

    二,,通过普通的路由调用,,路径写到http://localhost:29920/api/Players  即   Api/controller  为止

  2. unity3d c# http 请求json数据解析

    using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Net ...

  3. CentOS6.5上Zabbix3.0的RPM安装【一】-安装并配置Server

    一.Environment OS:CentOS6.5 64bit [桌面版安装] Server端:192.168.201.109 ServerName Clinet端:192.168.201.199 ...

  4. WP8.1&UWP手机设备对状态栏操作

    改UWP和WP8.1手机设备的状态栏.首先先说较为普遍的WP8.1设备:首先添加引用:using Windows.UI.ViewManagement;其次就可以使用StatusBar了,它提供了以下方 ...

  5. Miller-Rabin素数测试

    Miller-Rabin素数测试 给出一个小于1e18的数,问它是否为质数?不超过50组询问.hihocoder 我是真的菜,为了不误导他人,本篇仅供个人使用. 首先,一个1e18的数,朴素\(O(\ ...

  6. 洛谷P2606 [ZJOI2010]排列计数(数位dp)

    题目描述 称一个1,2,...,N的排列P1,P2...,Pn是Magic的,当且仅当2<=i<=N时,Pi>Pi/2. 计算1,2,...N的排列中有多少是Magic的,答案可能很 ...

  7. 使用remove_constants工具查看Oracle是否使用绑定变量

    https://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1163635055580 http://blog.csdn.n ...

  8. 10.17(山东多校联合模拟赛 day1)

    山东多校联合模拟赛 day1 题不难 rect [问题描述] 给出圆周上的 N 个点, 请你计算出以这些点中的任意四个为四个角,能构成多少个矩形. 点的坐标是这样描述的, 给定一个数组 v[1..N] ...

  9. 牛客nowcoder NOIP普及组第三场

    qtmd AK了 直接题解吧 题目链接 A-十七边形 牛牛想在一个半径为r的圆中,找到一个内接的十七边形,使他的面积最大.输入半径r,输出最大的面积. 1 <= r <= 10000 在1 ...

  10. 解决dubbo注册zookepper服务IP乱入问题的三种方式

    最近做一个项目引入了dubbo+zookepper的分布式服务治理框架.在应用的发布的时候出现一个怪问题.zookepper服务是起在开发服务器192.168.23.180上.本机起应用服务提供者注册 ...