题面:The Pilots Brothers’refrigerator

题目大意

”飞行员兄弟“这个游戏,需要玩家打开一个有着16把手的冰箱。
每个把手有且只有两种状态:打开(−-−)或关闭(+++)。
只有当所有把手都打开时,冰箱才能打开。
把手可以表示为一个 4×44×44×4 的矩阵,矩阵上的每个点 (i,j)(i,j)(i,j) 代表一个把手。
现在,玩家可以改变矩阵上任何位置的把手状态,但是改变了一个位置的状态后,该位置相应的行和列的状态都会改变。
求:打开冰箱所需的最小改变把手状态的次数是多少?

思路

根据题意,可以很清晰的得到,如果要改变一个位置的状态,该位置必须被改动奇数次才可以,如果是偶数次相当于没有改变状态。
那么如何改变每一个 ‘+++’ 呢?

稍微模拟一下,可以发现,当我们遇到一个 ‘+++’ 时,将该位置的行列都只改变一次(’+++'位置也只改变一次),则 ‘+++’ 位置被改变了 777 次,该位置上的行列被改变了 444 次,其他位置被改变了 222 次。如此就可以只改变 ‘+++’ 位置的状态。

于是就得出一个简单算法,即枚举每个位置的状态,如果该位置是 '+++’,则改变当前位置上的所有行列。最终得到的状态里,所有奇数次的位置都是要被操作的位置。此算法只能用在 NNN 为偶数的情况。

代码

#include <bits/stdc++.h>
#define sc scanf
#define pf printf
using namespace std;
typedef pair<int, int> PII;
string str[5];
bool mark[5][5];
vector<PII> ans;
int main()
{memset(mark, false, sizeof mark);for(int i = 0; i < 4; i++)  cin >> str[i];for(int i = 0; i < 4; i++)for(int j = 0; j < 4; j++) {if(str[i][j] == '+') {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];}}}for(int i = 0; i < 4; i++)for(int j = 0; j < 4; j++)if(mark[i][j])  ans.push_back({i+1,j+1});pf("%d\n", ans.size());for(int i = 0; i < ans.size(); i++)pf("%d %d\n", ans[i].first, ans[i].second);return 0;
}

The Pilots Brothers‘ refrigerator(思维)相关推荐

  1. POJ 2965.The Pilots Brothers‘ refrigerator

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

  2. poj 2965 The Pilots Brothers' refrigerator

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

  3. ACM POJ 2965 The Pilots Brothers' refrigerator

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

  4. B - The Pilots Brothers' refrigerator

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

  5. POJ2965 The Pilots Brothers‘ refrigerator

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

  6. POJ-2965 The Pilots Brothers' refrigerator

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

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

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

  8. The Pilots Brothers' refrigerator - poj 2965

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

  9. The Pilots Brothers‘ Refrigerator(高效贪心)

    题目描述 The game "The Pilots Brothers: following the stripy elephant" has a quest where a pla ...

最新文章

  1. Bio+IT 爱好者社区,欢迎你!
  2. 新型量子计算机首个基本元件问世,扩展性更强运算速度更快
  3. 《自然》杂志:关于人类未来的工作,有三个最紧迫的问题
  4. grdraw显示区域 lisp_lisp函数按功能分类
  5. fastjson的使用问题
  6. leetcode 437. Path Sum III | 437. 路径总和 III(DFS,前缀和)
  7. 31行代码AC——PTA 求二叉树的叶子结点个数 (20分)——解题报告
  8. C语言调用WIN32 API学习之6鼠标与键盘响应
  9. arch linux界面优化,Archlinux 启动优化
  10. 服务器创建多个dhcp服务_如何在15分钟内创建无服务器服务
  11. Vue源码解析:Vue实例
  12. Thinkpadt450 win7下面禁用触摸板
  13. linux mysql skip_skip-grant-tables 修改linux的mysql忘记root密码
  14. 计算机木材染色 配色技术的应用技术,木材怎么染色?木材染色剂电脑配色方法...
  15. web微信授权登陆-配置篇
  16. html根据出生日期计算星座,0047 JavaScript实现根据输入日期计算所属星座
  17. matlab 关于interpreter的使用
  18. 【转载】TinyXML2使用教程
  19. 使用Console.log调试
  20. RS232和RS485接口的问答

热门文章

  1. 哥大sps学院有计算机,哥大的sps学院是什么意思
  2. vue项目通讯录_Vue实现类似通讯录功能(下)
  3. linux查看设备和硬盘序列号 ip mac地址
  4. 自损八百!美光停止供货华为
  5. 青岛 android培训哪家好,青岛android培训学习班
  6. 计算机启动老是检测硬盘怎么解决,开机出现硬盘检测是怎么回事 硬盘检测的解决方法...
  7. angularJS学习小结——filter
  8. Umeng—新浪登录问题
  9. APP被网信办点名下架还能重新上架吗?恢复上架流程请收好
  10. 记录Win10正确安装CUDA和cuDNN的过程(记录一些坑)