The Pilots Brothers' refrigerator开灯问题
同样,一个连蒙再猜翻译了半个多小时还翻译错了好多的让我自闭一天的题T^T
这个题的意思是给出四行四列的一个字符串,要将其中的“+”全部变为“-”,输出最少的变换方式。
一开始想到的是dfs,但做了半天除了一堆bug什么都没写出来,后来看题解才明白是什么意思。
我们假设(i,j)位置上的字符是“+”,辣么我们对第i行和第j列的所有字符都进行更换,结果是(i,j)位置换了7次,第i行和第j列的其他字符换了4次,其他位置的字符换了2次,只有(i,j)位置的“+”变为了“-”,因此,我们可以对所有的"+"所在的行和列进行该操作,找到最后为奇数的位置即可。
代码
#include<cstdio>
#include<cstring>
int main()
{char arr[5][5];int l[5][5];memset(l,0,sizeof(l));for(int i=1;i<=4;i++){scanf("%s",arr[i]);}for(int i=1;i<=4;i++){for(int j=0;j<4;j++){if(arr[i][j]=='+'){for(int k=1;k<=4;k++) //在该行和该列进行模拟相加{l[i][k-1]++;l[k][j]++;}l[i][j]--; //把多加的一次减去}}}int ans=0;for(int i=1;i<=4;i++){for(int j=0;j<4;j++){if(l[i][j]%2==1){ans++;}}}printf("%d\n",ans);for(int i=1;i<=4;i++){for(int j=0;j<4;j++){if(l[i][j]%2==1){printf("%d %d\n",i,j+1);}}}return 0;
}
要注意这里有两个坑(虽然说我犯了各位巨巨们不一定犯,但还是说出来比较好)一个是(i,j)位置上在按照行和列相加时可能被多加了一次,另一个是如果按照行输入字符串时默认下标是0-3而不是1-4,这里在写代码时一定要注意(不同的方法有不同结果,可能影响也可能不影响)。
The Pilots Brothers' refrigerator开灯问题相关推荐
- POJ 2965.The Pilots Brothers‘ refrigerator
POJ 2965.The Pilots Brothers' refrigerator Ideas 题意:给你4*4的矩阵.每个点有两种状态,+代表关,-代表开.每个点有一个操作就是该点所在行列所有状态 ...
- ACM POJ 2965 The Pilots Brothers' refrigerator
http://poj.org/problem?id=2965 The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65 ...
- POJ2965 The Pilots Brothers‘ refrigerator
POJ2965 The Pilots Brothers' refrigerator 题干 Description Input Output Sample Input Sample Output 题意 ...
- poj 2965 The Pilots Brothers' refrigerator
http://poj.org/problem?id=2965 poj 1753扩展,dfs+枚举,不过加了一个路径. The Pilots Brothers' refrigerator Time Li ...
- B - The Pilots Brothers' refrigerator
B - The Pilots Brothers' refrigerator 文章目录 B - The Pilots Brothers' refrigerator 题目描述: Input: Output ...
- The Pilots Brothers‘ refrigerator(思维)
题面:The Pilots Brothers'refrigerator 题目大意 "飞行员兄弟"这个游戏,需要玩家打开一个有着16把手的冰箱. 每个把手有且只有两种状态:打开(−- ...
- POJ-2965 The Pilots Brothers' refrigerator
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27917 A ...
- The Pilots Brothers' refrigerator - poj 2965
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20325 Accepted: 7830 Special Judge ...
- 【POJ - 2965】The Pilots Brothers' refrigerator(暴力枚举,思维)
题干: The game "The Pilots Brothers: following the stripy elephant" has a quest where a play ...
最新文章
- zabbix企业应用之low level discovery监控磁盘吞吐量与iops
- java build.gradle 详解_java – Gradle构建失败[无法解析配置的所有依赖项’:compile’.]...
- 小学生学python-小学生都学Python了,你还不知道如何开始
- Button的使用(六):ToggleButton
- mos管工作原理_筋膜枪原理与筋膜枪方案,和筋膜枪烧mos管原理。推荐使用mos管 AP15G04NF...
- PHP中上传文件文件名乱码
- matlab中腐蚀图像的编写,Matlab实现二值图像的腐蚀算法源代码
- python--递归计算n的价乘
- 8g内存够吗 rust_618已过半,这些白菜价内存你买到了吗?最便宜的8G不到120元
- 针对ASP.NET MVC的SEO优化笔记
- CGO磁盘管理For流星无语
- 评微软裁员测试:自动化测试并不能代替人工
- TiDB 源码阅读系列文章(二十)Table Partition
- Hadoop HDFS 实现原理图文详解
- vbm 分析_vbm8_r435 脑功能数据分析处理实用软件,基于SPM 来运行 matlab 238万源代码下载- www.pudn.com...
- Oracle用户管理的备份与恢复(冷热)
- 拦截器、过滤器、监听器
- 横空出世IDEA画图神器来了,比Visio快10倍
- Error response from daemon: pull access denied for registey, repository does not exist or may requir
- C. Carrying Conundrum(找规律)
热门文章
- 【模电笔记】第一章3、4晶体三极管、场效应管
- 伯凡日知录--一万小时定律(第一天更新)
- 美剧中的英文粗语脏话知多少?
- QuickBooks 2007 All-in-One Desk Reference For Dummies
- coreldraw的线条怎么变成圆头_智能设计 | 建模仿真(3):力学仿真
- DirectX游戏开发之3D角色动起(下)
- 如何学好iphone游戏开发
- 手机辐射危害盘点:可降低男性精子活性
- 面试某东测试岗:“如果开发的Bug比较多,你会如何处理?”
- 183套免费简历模板,助大伙找个好工作