HDU——Cover——————【技巧】
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
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
题目大意:给你一个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——————【技巧】的更多相关文章
- hdu 5265 技巧题 O(nlogn)求n个数中两数相加取模的最大值
pog loves szh II Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)
http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...
- HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)
传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...
- hdu 4864 Task (贪心 技巧)
题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...
- HDU 6311 Cover (无向图最小路径覆盖)
HDU 6311 Cover (无向图最小路径覆盖) Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDU 5884 Sort(二分答案+计算WPL的技巧)
Sort Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- hdu 5386 Cover (暴力)
hdu 5386 Cover Description You have an matrix.Every grid has a color.Now there are two types of oper ...
- HDU 6150 - Vertex Cover | 2017 中国大学生程序设计竞赛 - 网络选拔赛
思路来自 ICPCCamp /* HDU 6150 - Vertex Cover [ 构造 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 给了你一个贪心法找最小覆盖的算法,构造一组 ...
- HDU -2674 N!Again(小技巧)
这道题有个小技巧,就是既然是n!,那么对2009求余,只要大于2009!,那么一定是0,在仔细想想会发现,根本到不了2009,只要到2009的最大质因数就行了,为什么呢?因为最大质因数是最大的一个不能 ...
随机推荐
- U-Net: Convolutional Networks for Biomedical Image Segmentation(理解+github代码)
github代码:https://github.com/Chet1996/pytorch-UNet 0 - Abstract 这篇文章是生物学会议ICMICCAI2015的文章,主要针对的是生物影像进 ...
- uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型
在nesc的代码中,你会看到很多你不认识的数据类型,比如uint8_t等.咋一看,好像是个新的数据类型,不过C语言(nesc是C的扩展)里面好像没有这种数据类型啊!怎么又是u又是_t的?很多人有这样的 ...
- Python字典基础知识补充
1.添加键值对 #!/usr/bin/env python i1 = {'k1':'cai' , 'k2':123} print(i1) i1['k3'] = 0 i1['k4'] = "r ...
- CompressFormat压缩性能
在产品应用场景内有个需求,Bitmap原图压缩保存.但是每次保存一个图片,需要500+ms.原本以为是sd卡写的慢.后来测试发现是图片压缩问题.试验过CompressFormat PNG和JPEG两种 ...
- loj #6485. LJJ 学二项式定理 (模板qwq)
$ \color{#0066ff}{ 题目描述 }$ LJJ 学完了二项式定理,发现这太简单了,于是他将二项式定理等号右边的式子修改了一下,代入了一定的值,并算出了答案. 但人口算毕竟会失误,他请来了 ...
- P3356 火星探险问题
\(\color{#0066ff}{题目描述}\) 火星探险队的登陆舱将在火星表面着陆,登陆舱内有多部障碍物探测车.登陆舱着陆后,探测车将离开登陆舱向先期到达的传送器方向移动.探测车在移动中还必须采集 ...
- git 创建、切换和提交新分支
查看本地分支 git branch 创建新的分支 git branch <newBranch> 切换分支 git checkout <branchName> 创建并切换分支 g ...
- matplotlib类
1.plt.subplot 在matplotlib下,一个Figure对象可以包含多个子图(Axes),可以使用subplot()快速绘制,其调用形式如下:subplot(numRows, numCo ...
- 15.Subtree of Another Tree(判断一棵树是否为另一颗树的子树)
Level: Easy 题目描述: Given two non-empty binary trees s and t, check whether tree t has exactly the s ...
- Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.
这是因为防火墙或者配置文件导致,无法启动的邮件服务!! 首先关闭防火墙! 修改配置文件 vim /etc/postfix/main.cf inet_protocols = ipv4 inet_inte ...