POJ 2965.The Pilots Brothers' refrigerator
来源:互联网 发布:spss剔除异常数据 编辑:程序博客网 时间:2024/06/06 01:29
题目:http://poj.org/problem?id=2965
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>#include <string.h>#include <bitset>using namespace std;bool a[4][4];vector<int> r;vector<int> c;int cnt;int mincnt;bool fliped[4][4];bool minfliped[4][4];void dfs(int x, int y){if(x == 4){bool flag = true;for(int i = 0; i < 4; i++)for(int j = 0; j < 4; j++)if(a[i][j]==false)flag = false;if(flag == true){if(cnt<mincnt){mincnt = cnt;for(int i = 0; i < 4; i++)for(int j = 0; j < 4; j++)minfliped[i][j] = fliped[i][j];}}return;} if(y!=3)dfs(x,y+1);else dfs(x+1,0);for(int i = 0; i < 4; i++){a[x][i] = !a[x][i];a[i][y] = !a[i][y];}a[x][y] = !a[x][y];cnt++;fliped[x][y] = true;if(y!=3)dfs(x,y+1);else dfs(x+1,0);fliped[x][y] = false;cnt--;for(int i = 0; i < 4; i++){a[x][i] = !a[x][i];a[i][y] = !a[i][y];}a[x][y] = !a[x][y];}int main(){for(int i = 0; i < 4; i++){for(int j = 0; j < 4; j++){char tmp;cin>>tmp;if(tmp=='+')a[i][j] = false;else a[i][j] = true;}}cnt = 0;mincnt = 2147483647;memset(fliped,false,sizeof(fliped));memset(minfliped,false,sizeof(minfliped));dfs(0,0);cout<<mincnt<<endl;for(int i = 0; i < 4; i++)for(int j = 0; j < 4; j++)if(minfliped[i][j])cout<<i+1<<' '<<j+1<<endl;}总结:
1.首先每个开关要不不动要不只操作一次(怎么想到的...)
2.因为1所以可以暴力深搜.
阅读全文
0 0
- poj 2965.The Pilots Brothers' refrigerator
- POJ 2965.The Pilots Brothers' refrigerator
- POJ 2965.The Pilots Brothers' refrigerator
- POJ 刷题系列:2965. The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- poj 2965The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator 枚举
- POJ-2965-The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965 The Pilots Brothers' refrigerator
- POJ-2965-The Pilots Brothers' refrigerator
- poj 2965 The Pilots Brothers' refrigerator
- POJ 2965:The Pilots Brothers' refrigerator
- Poj 2965 The Pilots Brothers' refrigerator
- poj The Pilots Brothers' refrigerator(DFS)
- 【显示过滤/排序结果】非常实用
- 使用RecyclerView实现动态添加头布局,脚布局
- IDEA开发中比较常用的快捷键
- SGU 115. Calendar (基姆拉尔森公式)
- ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-A-Visiting Peking University
- POJ 2965.The Pilots Brothers' refrigerator
- postgresql基于docker主从复制搭建
- 9.27
- 在外置移动硬盘中安装Win10
- 【IOS学习之常见问题】UIScrollView 不能滑动(ScrollView has ambiguous scrollable content height)
- 内网穿透技术详解 --- Java本地项目,可以让别人通过外网访问 (natapp、ngrok、nat123、花生壳等)
- define,const和enmu的区别
- ios-动态改变高度的注意点
- @RequestMapping注解的使用