POJ 2965 The Pilots Brothers' refrigerator(枚举+dfs)
来源:互联网 发布:淘宝 中药材 编辑:程序博客网 时间:2024/06/07 10:13
http://poj.org/problem?id=2965
分析:
和 POJ 1573 一样的题目 加一下路径记录 翻时候是它所在的行列都要翻
AC代码:
#include <stdio.h>#include <string.h>char map[20][20];int temp[20][20];int step;int flag;int judge(){ for (int i=0;i<4;i++){ for (int j=0;j<4;j++){ if(map[i][j]!='-') return 0; } } return 1;}void oper(int x,int y){ if (map[x][y]=='+') map[x][y]='-'; else map[x][y]='+'; for(int i=0;i<4;i++){ if (map[x][i]=='+') map[x][i]='-'; else map[x][i]='+';} for (int j=0;j<4;j++){if (map[j][y]=='+') map[j][y]='-'; else map[j][y]='+';}}void dfs(int x,int y,int count){ if(count==step){ if((flag=judge())){ printf ("%d\n",step); for (int i=0;i<4;i++){ for (int j=0;j<4;j++){ if(temp[i][j]) printf ("%d %d\n",i+1,j+1);}}} return ;}if(flag||x==4)return;oper(x,y);temp[x][y]=1; if(y<3) dfs(x,y+1,count+1); else dfs(x+1,0,count+1); temp[x][y]=0; oper(x,y); if(y<3) dfs(x,y+1,count); else dfs(x+1,0,count);}int main (){ memset(map,0,sizeof(map)); for (int i=0;i<4;i++){ scanf ("%s",map[i]); } for(step=0;step<=16;step++){ flag=0;memset(temp,0,sizeof(temp)); dfs(0,0,0); if(flag) break;} return 0;}
阅读全文
0 0
- POJ 2965 The Pilots Brothers' refrigerator【枚举+dfs】
- POJ 2965 The Pilots Brothers' refrigerator(dfs+枚举 || 规律)
- POJ 2965 The Pilots Brothers' refrigerator 枚举dfs
- POJ 2965-The Pilots Brothers' refrigerator(枚举&&DFS&&输出过程)
- POJ 2965 The Pilots Brothers' refrigerator(枚举+dfs)
- The Pilots Brothers' refrigerator(POJ 2965)(dfs枚举+状态压缩)
- POJ 2965 The Pilots Brothers' refrigerator(枚举+DFS)
- POJ 2965 The Pilots Brothers' refrigerator (DFS + 枚举)
- (枚举,dfs)The Pilots Brothers' refrigerator poj 2965
- POJ 2965 The Pilots Brothers' refrigerator(枚举+dfs)
- 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【枚举】
- The Pilots Brothers' refrigerator 枚举 Poj 2965
- Laravel 前台注册 阿里大于
- KMP总结
- Centos7安装vim8.0 + YouCompleteMe
- multiset<int, greater<int>> test 相关
- 欢迎使用CSDN-markdown编辑器
- POJ 2965 The Pilots Brothers' refrigerator(枚举+dfs)
- js技术--BOM(open,close,右下角固定悬浮框)
- python re模块
- HDU
- oracle定义数组类型
- java基础(六):类和对象(1)
- 4:--2相对定位
- 了解比特币(区块链)
- JSP的配置教程