POJ 2965.The Pilots Brothers’ refrigerator

Ideas

题意:给你4*4的矩阵。每个点有两种状态,+代表关,-代表开。每个点有一个操作就是该点所在行列所有状态翻转。问最少多少次可以打开全部开关,并且输出最少个数情况下翻转的点。

先梳理一下题目给的测试样例的操作步骤:

首先需要知道一点:一个开关翻转偶数次状态不变,翻转奇数次状态改变。(奇变偶不变)

然后再深入一步:要使一个为+的符号变为-,必须其相应的行和列的操作数为奇数。

如果+位置对应的行和列上每一个位置都进行一次操作,则整个图只有这个+位置的符号改变,其余都不会改变。

假如只有(1, 1)位置上为+,那么第一行和第一列全部翻转一遍之后,只有(1, 1)位置上变为-,其它位置没有改变。

设置一个4*4的整型数组mark,初值为零,用于记录每个位置的操作次数。

那么在每个+上的行和列的的位置都加1,也就是说这个+对应位置的行和列都翻转一遍,结果只有这个+位置变为-,其它不变。

最后,有些位置翻转了偶数次,没有改变,有些位置翻转了奇数次,这些位置就是要进行翻转的位置。

因此mark可以简化为bool类型的数组,为0或false表示翻转偶数次,为1或true表示翻转奇数次。

Code

C++

#include <cstring>
#include <iostream>using namespace std;bool mark[4][4];int main() {memset(mark, 0, sizeof(mark));for(int i = 0; i < 4; i++) {for(int j = 0; j < 4; j++) {char ch;cin >> ch;if(ch == '+') {mark[i][j] = !mark[i][j];for(int k = 0; k < 4; k++) {mark[i][k] = !mark[i][k];mark[k][j] = !mark[k][j];}}}}int step = 0;int p_i[16], p_j[16];for(int i = 0; i < 4; i++) {for(int j = 0; j < 4; j++) {if(mark[i][j]) {p_i[step] = i + 1;p_j[step] = j + 1;step++;}}}cout << step << endl;for(int i = 0; i < step; i++) {cout << p_i[i] << " " << p_j[i] << endl;}return 0;
}

POJ 2965.The Pilots Brothers‘ refrigerator相关推荐

  1. ACM POJ 2965 The Pilots Brothers' refrigerator

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

  2. poj 2965 The Pilots Brothers' refrigerator

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

  3. Poj 2965 The Pilots Brothers‘ refrigerator

    The game "The Pilots Brothers: following the stripy elephant" has a quest where a player n ...

  4. POJ - 2965 The Pilots Brothers' refrigerator(bfs+路径输出/思维+位运算)

    题目链接:点击查看 题目大意:给出一个4*4的矩阵,每个点都代表一个开关,'+'代表关,'-'代表开,每次操作可以任意改变一个开关(x,y)的状态,但代价是x行和y列的开关都要一起改变状态,题目要求将 ...

  5. POJ 2965 The Pilots Brothers' refrigerator

    这个题是一个枚举题. 用的是八皇后算法. 具体操作不说了. 下面是代码: #include <stdio.h> struct node {int x,y; }de[200],dr[200] ...

  6. poj 2965 The Pilots Brothers#39; refrigerator

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

  7. B - The Pilots Brothers' refrigerator

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

  8. POJ2965 The Pilots Brothers‘ refrigerator

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

  9. The Pilots Brothers‘ refrigerator(思维)

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

最新文章

  1. QTP的那些事--通过WMI获取session中的用户信息的验证码
  2. 4月23日遇到的问题
  3. PHP的简单跳转提示的实现
  4. LeetCode Super Ugly Number
  5. hbm2java和hbm2ddl的使用步骤
  6. CVX约束中定义中间变量或表达式
  7. Spring Boot 自动配置原理
  8. Educational Codeforces Round 112 E.Boring Segments-线段树+双指针
  9. 具有CompletableFuture的异步超时
  10. java中可重入锁的学习总结
  11. 从RedisTemplate中获得Jedis实例
  12. linux-type命令查看类型
  13. Sqlserver数据库还原.bak文件失败的两个问题
  14. linux内核奇遇记之md源代码解读之二
  15. rust第三人称视角插件_第三人称视角ThirdPerson Everything Mod
  16. Atitit 爬虫发展历史 在互联网发展初期,网站相对较少,信息查找比较容易。然而伴随互联网爆炸性的发展,普通网络用户想找到所需的资料简直如同大海捞针,这时为满足大众信息检索需求的专业搜索网站便应运
  17. 解散群通知怎么写_德云社演员私联初二女生,随后德云社全员退出粉丝群,什么情况?...
  18. 简单工厂模式-工厂模式-抽象工厂模式类图
  19. 7-3 A-B 本题要求你计算A−B。不过麻烦的是,A和B都是字符串 —— 即从字符串A中把字符串B所包含的字符全删掉,剩下的字符组成的就是字符串A−B。
  20. GDOI2018D2T1 谈笑风生

热门文章

  1. IIS7 经典模式和集成模式的区别分析
  2. 杂项-QRCode:ZXing
  3. BZOJ 2208[Jsoi2010]连通数
  4. PHP基础知识--函数
  5. 如何使用matplotlib绘制一个函数的图像
  6. struts2综合例子--------拦截器(登陆检查,日志记录),校验validate,
  7. CodeDom Assistant CodeDom的强大工具, 有些BUG修正了下,发到CodePlex,大家有需要的可以看看...
  8. Direct2D (35) : 通过 DirectWrite 获取字体列表
  9. python朋友圈自动点赞_基于AirTest+Python的ios自动化测试demo(微信朋友圈无限点赞)...
  10. C语言程序练习-L1-003 个位数统计 (15分)