同样,一个连蒙再猜翻译了半个多小时还翻译错了好多的让我自闭一天的题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开灯问题相关推荐

  1. POJ 2965.The Pilots Brothers‘ refrigerator

    POJ 2965.The Pilots Brothers' refrigerator Ideas 题意:给你4*4的矩阵.每个点有两种状态,+代表关,-代表开.每个点有一个操作就是该点所在行列所有状态 ...

  2. ACM POJ 2965 The Pilots Brothers' refrigerator

    http://poj.org/problem?id=2965 The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65 ...

  3. POJ2965 The Pilots Brothers‘ refrigerator

    POJ2965 The Pilots Brothers' refrigerator 题干 Description Input Output Sample Input Sample Output 题意 ...

  4. poj 2965 The Pilots Brothers' refrigerator

    http://poj.org/problem?id=2965 poj 1753扩展,dfs+枚举,不过加了一个路径. The Pilots Brothers' refrigerator Time Li ...

  5. B - The Pilots Brothers' refrigerator

    B - The Pilots Brothers' refrigerator 文章目录 B - The Pilots Brothers' refrigerator 题目描述: Input: Output ...

  6. The Pilots Brothers‘ refrigerator(思维)

    题面:The Pilots Brothers'refrigerator 题目大意 "飞行员兄弟"这个游戏,需要玩家打开一个有着16把手的冰箱. 每个把手有且只有两种状态:打开(−- ...

  7. POJ-2965 The Pilots Brothers' refrigerator

    The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27917 A ...

  8. The Pilots Brothers' refrigerator - poj 2965

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20325   Accepted: 7830   Special Judge ...

  9. 【POJ - 2965】The Pilots Brothers' refrigerator(暴力枚举,思维)

    题干: The game "The Pilots Brothers: following the stripy elephant" has a quest where a play ...

最新文章

  1. zabbix企业应用之low level discovery监控磁盘吞吐量与iops
  2. java build.gradle 详解_java – Gradle构建失败[无法解析配置的所有依赖项’:compile’.]...
  3. 小学生学python-小学生都学Python了,你还不知道如何开始
  4. Button的使用(六):ToggleButton
  5. mos管工作原理_筋膜枪原理与筋膜枪方案,和筋膜枪烧mos管原理。推荐使用mos管 AP15G04NF...
  6. PHP中上传文件文件名乱码
  7. matlab中腐蚀图像的编写,Matlab实现二值图像的腐蚀算法源代码
  8. python--递归计算n的价乘
  9. 8g内存够吗 rust_618已过半,这些白菜价内存你买到了吗?最便宜的8G不到120元
  10. 针对ASP.NET MVC的SEO优化笔记
  11. CGO磁盘管理For流星无语
  12. 评微软裁员测试:自动化测试并不能代替人工
  13. TiDB 源码阅读系列文章(二十)Table Partition
  14. Hadoop HDFS 实现原理图文详解
  15. vbm 分析_vbm8_r435 脑功能数据分析处理实用软件,基于SPM 来运行 matlab 238万源代码下载- www.pudn.com...
  16. Oracle用户管理的备份与恢复(冷热)
  17. 拦截器、过滤器、监听器
  18. 横空出世IDEA画图神器来了,比Visio快10倍
  19. Error response from daemon: pull access denied for registey, repository does not exist or may requir
  20. C. Carrying Conundrum(找规律)

热门文章

  1. 【模电笔记】第一章3、4晶体三极管、场效应管
  2. 伯凡日知录--一万小时定律(第一天更新)
  3. 美剧中的英文粗语脏话知多少?
  4. QuickBooks 2007 All-in-One Desk Reference For Dummies
  5. coreldraw的线条怎么变成圆头_智能设计 | 建模仿真(3):力学仿真
  6. DirectX游戏开发之3D角色动起(下)
  7. 如何学好iphone游戏开发
  8. 手机辐射危害盘点:可降低男性精子活性
  9. 面试某东测试岗:“如果开发的Bug比较多,你会如何处理?”
  10. 183套免费简历模板,助大伙找个好工作